-- Client Side --

local tdm_menu = {}

SelectedTeamID = 0
SelectedWeaponIs = 0
SelectedModelIs = 0
SelectedMapIs = 0
SelectOneEntity = nil
DEFAULT_GOAL_VALUE = 0
DEFAULT_DMorTDM_VALUE = 0
DEFAULT_FF_VALUE2 = 0
GetValueForPoints = "999999999999999"
GetValueForRank = "You should not be able to see this"
StatKillsP = 999999999999999
StatDeathP = 999999999999999
StatTimeP = 999999999999999
TeamListing = 999999999999999


function tdm_menu.initialize() -- The entire menu

tdm_menu.MainMenuFrame = vgui.Create( "DFrame" )
tdm_menu.MainMenuFrame:SetSize( 600, 250 )
tdm_menu.MainMenuFrame:SetTitle("Team Deathmatch Menu: Version "..GameModeVersion )
tdm_menu.MainMenuFrame:Center()
tdm_menu.MainMenuFrame:ShowCloseButton( false )
tdm_menu.MainMenuFrame:SetDraggable( false )
--tdm_menu.MainMenuFrame:MakePopup()
function tdm_menu.MainMenuFrame:Paint( w, h )
	draw.RoundedBox( 0, 0, 0, w, h, Color(team.GetColor(LocalPlayer():Team()).r,team.GetColor(LocalPlayer():Team()).g,team.GetColor(LocalPlayer():Team()).b,50))
	surface.SetDrawColor(0,0,0)
	surface.DrawOutlinedRect(1,1,w-1,h-1)
end


-- This Creates A New Tab
tdm_menu.MainMenuSheet = vgui.Create( "DPropertySheet", tdm_menu.MainMenuFrame )
tdm_menu.MainMenuSheet:SetPos( 5, 27 )
tdm_menu.MainMenuSheet:SetSize( 590, 217 )
-- Team Tab
tdm_menu.TabOne = vgui.Create( "DPanelList" )
tdm_menu.TabOne:SetPos( 0, 0 )
tdm_menu.TabOne:SetSize( tdm_menu.MainMenuSheet:GetWide(), tdm_menu.MainMenuSheet:GetTall() )
tdm_menu.TabOne:SetSpacing( 5 )
tdm_menu.TabOne:EnableHorizontal( false )
tdm_menu.TabOne:EnableVerticalScrollbar( true )
-- Team Tab
tdm_menu.TabTwo = vgui.Create( "DPanelList" )
tdm_menu.TabTwo:SetPos( 0, 0 )
tdm_menu.TabTwo:SetSize( tdm_menu.MainMenuSheet:GetWide(), tdm_menu.MainMenuSheet:GetTall() )
tdm_menu.TabTwo:SetSpacing( 5 )
tdm_menu.TabTwo:EnableHorizontal( false )
tdm_menu.TabTwo:EnableVerticalScrollbar( true )
-- Entities Tab
tdm_menu.TabFive = vgui.Create( "DPanelList" )
tdm_menu.TabFive:SetPos( 0, 0 )
tdm_menu.TabFive:SetSize( tdm_menu.MainMenuSheet:GetWide(), tdm_menu.MainMenuSheet:GetTall() )
tdm_menu.TabFive:SetSpacing( 5 )
tdm_menu.TabFive:EnableHorizontal( false )
tdm_menu.TabFive:EnableVerticalScrollbar( true )
-- Game Tab
tdm_menu.TabSix = vgui.Create( "DPanelList" )
tdm_menu.TabSix:SetPos( 0, 0 )
tdm_menu.TabSix:SetSize( tdm_menu.MainMenuSheet:GetWide(), tdm_menu.MainMenuSheet:GetTall() )
tdm_menu.TabSix:SetSpacing( 5 )
tdm_menu.TabSix:EnableHorizontal( false )
tdm_menu.TabSix:EnableVerticalScrollbar( true )
-- Point Shop
tdm_menu.TabSeven = vgui.Create( "DPanelList" )
tdm_menu.TabSeven:SetPos( 0, 0 )
tdm_menu.TabSeven:SetSize( tdm_menu.MainMenuSheet:GetWide(), tdm_menu.MainMenuSheet:GetTall() )
tdm_menu.TabSeven:SetSpacing( 5 )
tdm_menu.TabSeven:EnableHorizontal( false )
tdm_menu.TabSeven:EnableVerticalScrollbar( true )
-- Point Shop
tdm_menu.TabEight = vgui.Create( "DPanelList" )
tdm_menu.TabEight:SetPos( 0, 0 )
tdm_menu.TabEight:SetSize( tdm_menu.MainMenuSheet:GetWide(), tdm_menu.MainMenuSheet:GetTall() )
tdm_menu.TabEight:SetSpacing( 5 )
tdm_menu.TabEight:EnableHorizontal( false )
tdm_menu.TabEight:EnableVerticalScrollbar( true )
-- ChangeLogs Tab
tdm_menu.TabFour = vgui.Create( "DPanelList" )
tdm_menu.TabFour:SetPos( 0, 0 )
tdm_menu.TabFour:SetSize( tdm_menu.MainMenuSheet:GetWide(), tdm_menu.MainMenuSheet:GetTall() )
tdm_menu.TabFour:SetSpacing( 5 )
tdm_menu.TabFour:EnableHorizontal( false )
tdm_menu.TabFour:EnableVerticalScrollbar( true )
-- Credits TAb
tdm_menu.TabThree = vgui.Create( "DPanelList" )
tdm_menu.TabThree:SetPos( 0, 0 )
tdm_menu.TabThree:SetSize( tdm_menu.MainMenuSheet:GetWide(), tdm_menu.MainMenuSheet:GetTall() )
tdm_menu.TabThree:SetSpacing( 5 )
tdm_menu.TabThree:EnableHorizontal( false )
tdm_menu.TabThree:EnableVerticalScrollbar( true )



/*
LINE BREAK
*/


-- TAB ONE - Choose a Team Label
tdm_menu.ChooseATeam = vgui.Create("DLabel", tdm_menu.TabOne)
tdm_menu.ChooseATeam:SetPos(10,5)
tdm_menu.ChooseATeam:SetColor( Color( 0, 0, 0, 255 ) )
tdm_menu.ChooseATeam:SetFont("default")
tdm_menu.ChooseATeam:SetText("Choose a Team:")
tdm_menu.ChooseATeam:SizeToContents()
-- TAB ONE - Choose a Team
tdm_menu.MenuButton = vgui.Create("DButton", tdm_menu.TabOne)
tdm_menu.MenuButton:SetText( "Team Chooser:" )
tdm_menu.MenuButton:SetPos(7, 20)
tdm_menu.MenuButton:SetSize( 150, 25 )
tdm_menu.MenuButton.DoClick = function ( btn )
tdm_menu.MenuButtonOptions = DermaMenu()
for k,v in pairs(AddTeams2) do
	if k != 0 and k < 1000 then
		tdm_menu.MenuButtonOptions:AddOption(team.GetName(k), function()  
			RunConsoleCommand( "TDMChangeTeam", tonumber(k) )
		end )		
		tdm_menu.MenuButtonOptions:Open()
	end
end	
end
-- TAB ONE - Player Lists
tdm_menu.PlayerListing = vgui.Create("DListView")
tdm_menu.PlayerListing:SetParent(tdm_menu.TabOne)
tdm_menu.PlayerListing:SetPos(7, 50)
tdm_menu.PlayerListing:SetSize(250,127)
tdm_menu.PlayerListing:SetMultiSelect(false)
tdm_menu.PlayerListing:AddColumn("Name")
tdm_menu.PlayerListing:AddColumn("Kills")
tdm_menu.PlayerListing:AddColumn("Deaths")
tdm_menu.PlayerListing:AddColumn("Team")
for k,v in pairs(player.GetAll()) do
	tdm_menu.PlayerListing:AddLine(v:Nick(),v:Frags(),v:Deaths(),team.GetName(v:Team()))
end
-- TAB ONE - Model Viewer Frame
tdm_menu.ModelViewerFrame = vgui.Create( "DFrame", tdm_menu.TabOne )
tdm_menu.ModelViewerFrame:SetPos( 420, 5 )
tdm_menu.ModelViewerFrame:SetSize( 150, 170 )
tdm_menu.ModelViewerFrame:ShowCloseButton( false )
tdm_menu.ModelViewerFrame:SetTitle("" )
tdm_menu.ModelViewerFrame.Paint = function()
	draw.RoundedBox( 8, 0, 0, tdm_menu.ModelViewerFrame:GetWide(), tdm_menu.ModelViewerFrame:GetTall(), Color(team.GetColor(LocalPlayer():Team()).r,team.GetColor(LocalPlayer():Team()).g,team.GetColor(LocalPlayer():Team()).b,100) )
end
-- TAB ONE - Model Viewer
tdm_menu.icon = vgui.Create( "DModelPanel", tdm_menu.TabOne )
tdm_menu.icon:SetModel( LocalPlayer():GetModel() )
tdm_menu.icon:SetPos(300, -40)
tdm_menu.icon:SetSize( 400, 400 )
tdm_menu.icon:SetCamPos( Vector( 50, 100, 120 ) )
tdm_menu.icon:SetLookAt( Vector( 0, 0, 0 ) )
tdm_menu.icon.DoClick = function()
    tdm_menu.IconOptions = DermaMenu() -- Creates the menu
	for k, v in pairs(TeamModels) do
		if LocalPlayer():Team() == tonumber(v.id) then
		local exp = string.Explode(",",v.tmodels)
			for r, b in pairs(exp) do
				tdm_menu.IconOptions:AddOption(b, function() 
				tdm_menu.icon:SetModel( b )
				RunConsoleCommand( "TDMChangeModel", b ) 
				end )
			end
		end
	end
    tdm_menu.IconOptions:Open()
end
-- TAB ONE - Model Viewer Label
tdm_menu.ModelIcon = vgui.Create("DLabel", tdm_menu.TabOne)
tdm_menu.ModelIcon:SetPos(450,10)
tdm_menu.ModelIcon:SetColor( Color( 0, 0, 0, 255 ) )
tdm_menu.ModelIcon:SetFont("default")
tdm_menu.ModelIcon:SetText("Your Team Model(s):")
tdm_menu.ModelIcon:SizeToContents()



/*
LINE BREAK
*/



-- TAB Two - Teams Lists
tdm_menu.TeamListing = vgui.Create("DListView")
tdm_menu.TeamListing:SetParent(tdm_menu.TabTwo)
tdm_menu.TeamListing:SetPos(7, 7)
tdm_menu.TeamListing:SetSize(125,100)
tdm_menu.TeamListing:AddColumn("ID")
tdm_menu.TeamListing:AddColumn("Teams")
tdm_menu.TeamListing:SetMultiSelect(false)
for k,v in pairs(AddTeams2) do
	tdm_menu.TeamListing:AddLine(k,v.tname)
end

-- TAB Two - List Models
tdm_menu.ModelListing = vgui.Create("DListView")
tdm_menu.ModelListing:SetParent(tdm_menu.TabTwo)
tdm_menu.ModelListing:SetPos(139, 7)
tdm_menu.ModelListing:SetSize(220,100)
tdm_menu.ModelListing:AddColumn("Selected Team's Models")
tdm_menu.ModelListing:SetMultiSelect(false)

-- TAB Two - List Weapons
tdm_menu.WeaponsListing = vgui.Create("DListView")
tdm_menu.WeaponsListing:SetParent(tdm_menu.TabTwo)
tdm_menu.WeaponsListing:SetPos(366, 7)
tdm_menu.WeaponsListing:SetSize(200,100)
tdm_menu.WeaponsListing:AddColumn("Selected Team's Weapons")
tdm_menu.WeaponsListing:SetMultiSelect(false)



-- TAB TWO - Get Model/Weapons Selected
tdm_menu.TeamListing.OnClickLine = function(_, line, WhatSelected)
SelectedTeamID = 0
SelectedWeaponIs = 0
SelectedModelIs = 0
	if IsMenuOpenOrClosedCHANGE == 1 then
		IsMenuOpenOrClosedCHANGE = 0
		tdm_menu.ModelChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADD == 1 then
		IsMenuOpenOrClosedADD = 0
		tdm_menu.ModelAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedEDITTeam == 1 then
		IsMenuOpenOrClosedEDITTeam = 0
		tdm_menu.TeamEditF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVE == 1 then
		IsMenuOpenOrClosedREMOVE = 0
		tdm_menu.ModelRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDWep == 1 then
		IsMenuOpenOrClosedADDWep = 0
		tdm_menu.WeaponAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVEWep == 1 then
		IsMenuOpenOrClosedREMOVEWep = 0
		tdm_menu.WeaponRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGEWep == 1 then
		IsMenuOpenOrClosedCHANGEWep = 0
		tdm_menu.WeaponChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDTeam == 1 then
		IsMenuOpenOrClosedADDTeam = 0
		tdm_menu.TeamAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVETeam == 1 then
		IsMenuOpenOrClosedREMOVETeam = 0
		tdm_menu.TeamRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	else
	
	SelectOneTeamID = line:GetValue(1)
	SelectOneTeam = line:GetValue(2)
	
	tdm_menu.ModelListing:Clear()
	tdm_menu.WeaponsListing:Clear()
	
	SelectedTeamID = 1
	
		for k, v in pairs(TeamModels) do
			if line:GetValue(1) == v.id then
			CurrentTeamID = v.id
			
			local exp = string.Explode(",",v.tmodels)
			local exp2 = string.Explode(",",v.tweapons)
			GetModelListData = {}
			GetWeaponListData = {}
			GetWeaponsListData = {}
				for r, b in pairs(exp) do
					tdm_menu.ModelListing:AddLine(b)
					GetModelListData[r] = {
					Models = b
					}
				end
				for r, b in pairs(exp2) do
					tdm_menu.WeaponsListing:AddLine(b)
					GetWeaponsListData[r] = {
					Weapons = b
					}
				end
			end
		end
	end
end



-- Add Teams
tdm_menu.TeamAddButton = vgui.Create( "DButton", tdm_menu.TabTwo )
tdm_menu.TeamAddButton:SetSize( 125, 20 )
tdm_menu.TeamAddButton:SetPos( 7, 111 )
tdm_menu.TeamAddButton:SetText( "Add" )
tdm_menu.TeamAddButton.DoClick = function( button )
	if LocalPlayer():IsSuperAdmin() == false then
		IsMenuOpenOrClosedADDTeam = 0
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You are not an admin!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGE == 1 then
		IsMenuOpenOrClosedCHANGE = 0
		tdm_menu.ModelChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return	
	elseif IsMenuOpenOrClosedEDITTeam == 1 then
		IsMenuOpenOrClosedEDITTeam = 0
		tdm_menu.TeamEditF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADD == 1 then
		IsMenuOpenOrClosedADD = 0
		tdm_menu.ModelAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVE == 1 then
		IsMenuOpenOrClosedREMOVE = 0
		tdm_menu.ModelRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDWep == 1 then
		IsMenuOpenOrClosedADDWep = 0
		tdm_menu.WeaponAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVEWep == 1 then
		IsMenuOpenOrClosedREMOVEWep = 0
		tdm_menu.WeaponRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGEWep == 1 then
		IsMenuOpenOrClosedCHANGEWep = 0
		tdm_menu.WeaponChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDTeam == 1 then
		IsMenuOpenOrClosedADDTeam = 0
		tdm_menu.TeamAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVETeam == 1 then
		IsMenuOpenOrClosedREMOVETeam = 0
		tdm_menu.TeamRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	else
		
		
		IsMenuOpenOrClosedADDTeam = 1
		-- Entry Frame
		tdm_menu.TeamAddF = vgui.Create( "DFrame" )
		tdm_menu.TeamAddF:SetSize( 500, 240 )
		tdm_menu.TeamAddF:SetTitle("Team Adder")
		tdm_menu.TeamAddF:Center()
		tdm_menu.TeamAddF:ShowCloseButton( false )
		tdm_menu.TeamAddF:SetDraggable( false )
		tdm_menu.TeamAddF:MakePopup()

		-- Add Label
		tdm_menu.TeamAddLabel = vgui.Create("DLabel", tdm_menu.TeamAddF )
		tdm_menu.TeamAddLabel:SetPos(18,27)
		tdm_menu.TeamAddLabel:SetColor( Color( 0, 0, 0, 255 ) )
		tdm_menu.TeamAddLabel:SetText("Enter Team Name:")
		tdm_menu.TeamAddLabel:SizeToContents()
		
		-- Entry Box Team
		tdm_menu.TeamEntryAddBox = vgui.Create( "DTextEntry", tdm_menu.TeamAddF)
		tdm_menu.TeamEntryAddBox:SetPos( 15,43 )
		tdm_menu.TeamEntryAddBox:SetTall( 25 )
		tdm_menu.TeamEntryAddBox:SetWide( 200 )
		tdm_menu.TeamEntryAddBox:SetEnterAllowed( false )
		tdm_menu.TeamEntryAddBox:SetValue( "Team Name" )
		
		-- Add Label
		tdm_menu.TeamAddLabe2 = vgui.Create("DLabel", tdm_menu.TeamAddF )
		tdm_menu.TeamAddLabe2:SetPos(18,77)
		tdm_menu.TeamAddLabe2:SetColor( Color( 0, 0, 0, 255 ) )
		tdm_menu.TeamAddLabe2:SetText("Enter First Model:")
		tdm_menu.TeamAddLabe2:SizeToContents()
		
		-- Entry Box Team
		tdm_menu.TeamEntryAddBox2 = vgui.Create( "DTextEntry", tdm_menu.TeamAddF)
		tdm_menu.TeamEntryAddBox2:SetPos( 15,93 )
		tdm_menu.TeamEntryAddBox2:SetTall( 25 )
		tdm_menu.TeamEntryAddBox2:SetWide( 200 )
		tdm_menu.TeamEntryAddBox2:SetEnterAllowed( false )
		tdm_menu.TeamEntryAddBox2:SetValue( "models/player/Group01/male_01.mdl" )
		
		-- Add Label
		tdm_menu.TeamAddLabe3 = vgui.Create("DLabel", tdm_menu.TeamAddF )
		tdm_menu.TeamAddLabe3:SetPos(18,127)
		tdm_menu.TeamAddLabe3:SetColor( Color( 0, 0, 0, 255 ) )
		tdm_menu.TeamAddLabe3:SetText("Enter First Weapon:")
		tdm_menu.TeamAddLabe3:SizeToContents()
		
		-- Entry Box Team
		tdm_menu.TeamEntryAddBox3 = vgui.Create( "DTextEntry", tdm_menu.TeamAddF)
		tdm_menu.TeamEntryAddBox3:SetPos( 15,143 )
		tdm_menu.TeamEntryAddBox3:SetTall( 25 )
		tdm_menu.TeamEntryAddBox3:SetWide( 200 )
		tdm_menu.TeamEntryAddBox3:SetEnterAllowed( false )
		tdm_menu.TeamEntryAddBox3:SetValue( "weapon_cs_deagle" )
		
		-- Color Wheel
		tdm_menu.ColorWheel = vgui.Create( "DColorMixer", tdm_menu.TeamAddF);
		tdm_menu.ColorWheel:SetSize( 225, 200);
		tdm_menu.ColorWheel:SetPos( 265, 30 );
		tdm_menu.ColorWheel:SetColor(Color(255,255,255,255))
		
		-- Close Button Team
		tdm_menu.TeamAddButtClose = vgui.Create( "DButton", tdm_menu.TeamAddF )
		tdm_menu.TeamAddButtClose:SetSize( 35, 20 )
		tdm_menu.TeamAddButtClose:SetPos( 460, 3 )
		tdm_menu.TeamAddButtClose:SetText( "Close" )
		tdm_menu.TeamAddButtClose.DoClick = function( button )
			tdm_menu.TeamAddF:Close()
			IsMenuOpenOrClosedADDTeam = 0
		end
		
		-- Button Team
		tdm_menu.TeamAddButt = vgui.Create( "DButton", tdm_menu.TeamAddF )
		tdm_menu.TeamAddButt:SetSize( 200, 50 )
		tdm_menu.TeamAddButt:SetPos( 15, 180 )
		tdm_menu.TeamAddButt:SetText( "Add" )
		tdm_menu.TeamAddButt.DoClick = function( button )
		if tdm_menu.TeamEntryAddBox:GetValue() == "" then
			Derma_Message("The team can't be empty, enter a valid team!", "[TDM] Error", "OK")
			surface.PlaySound( "apptdm/error.mp3" )
			return
		end
			for k, v in pairs(AddTeams2) do
				if tdm_menu.TeamEntryAddBox:GetValue() == v.tname then
					Derma_Message("The team can not be the same as another team in the list!", "[TDM] Error", "OK")
					surface.PlaySound( "apptdm/error.mp3" )
					return
				else
				end
			end
			
			
			net.Start("GetTeamListData55")
				net.WriteString(tdm_menu.TeamEntryAddBox:GetValue())
				net.WriteTable(tdm_menu.ColorWheel:GetColor())
				net.WriteString(tdm_menu.TeamEntryAddBox2:GetValue())
				net.WriteString(tdm_menu.TeamEntryAddBox3:GetValue())
			net.SendToServer()
			
			surface.PlaySound( "apptdm/success.mp3" )
			
			tdm_menu.TeamAddF:Close()
			IsMenuOpenOrClosedADDTeam = 0
			Derma_Message("You have successfully submitted the change!", "Team Deathmatch Gamemode", "OK")
		end
	end
end

-- Change Teams
tdm_menu.TeamChangeButton = vgui.Create( "DButton", tdm_menu.TabTwo )
tdm_menu.TeamChangeButton:SetSize( 125, 20 )
tdm_menu.TeamChangeButton:SetPos( 7, 159 )
tdm_menu.TeamChangeButton:SetText( "Edit" )
tdm_menu.TeamChangeButton.DoClick = function( button )
	if LocalPlayer():IsSuperAdmin() == false then
		IsMenuOpenOrClosedEDITTeam = 0
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You are not an admin!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGE == 1 then
		IsMenuOpenOrClosedCHANGE = 0
		tdm_menu.ModelChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedEDITTeam == 1 then
		IsMenuOpenOrClosedEDITTeam = 0
		tdm_menu.TeamEditF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADD == 1 then
		IsMenuOpenOrClosedADD = 0
		tdm_menu.ModelAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVE == 1 then
		IsMenuOpenOrClosedREMOVE = 0
		tdm_menu.ModelRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDWep == 1 then
		IsMenuOpenOrClosedADDWep = 0
		tdm_menu.WeaponAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVEWep == 1 then
		IsMenuOpenOrClosedREMOVEWep = 0
		tdm_menu.WeaponRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGEWep == 1 then
		IsMenuOpenOrClosedCHANGEWep = 0
		tdm_menu.WeaponChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDTeam == 1 then
		IsMenuOpenOrClosedADDTeam = 0
		tdm_menu.TeamAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVETeam == 1 then
		IsMenuOpenOrClosedREMOVETeam = 0
		tdm_menu.TeamRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif SelectedTeamID == 0 then
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You have not selected a team to delete!", "[TDM] Error", "OK")
		return
	else
		
		
		XPos = nil 
		YPos = nil 
		ZPos = nil 
		IsMenuOpenOrClosedEDITTeam = 1
		-- Entry Frame
		tdm_menu.TeamEditF = vgui.Create( "DFrame" )
		tdm_menu.TeamEditF:SetSize( 500, 240 )
		tdm_menu.TeamEditF:SetTitle("TEAM: ["..team.GetName(CurrentTeamID).."] Team Edit")
		tdm_menu.TeamEditF:Center()
		tdm_menu.TeamEditF:ShowCloseButton( false )
		tdm_menu.TeamEditF:SetDraggable( false )
		tdm_menu.TeamEditF:MakePopup()

		-- Add Label
		tdm_menu.TeamChangeLabel = vgui.Create("DLabel", tdm_menu.TeamEditF )
		tdm_menu.TeamChangeLabel:SetPos(18,27)
		tdm_menu.TeamChangeLabel:SetColor( Color( 0, 0, 0, 255 ) )
		tdm_menu.TeamChangeLabel:SetText("Enter Team Name:")
		tdm_menu.TeamChangeLabel:SizeToContents()
		
		-- Entry Box Team
		tdm_menu.TeamEntryEditBox = vgui.Create( "DTextEntry", tdm_menu.TeamEditF)
		tdm_menu.TeamEntryEditBox:SetPos( 15,43 )
		tdm_menu.TeamEntryEditBox:SetTall( 25 )
		tdm_menu.TeamEntryEditBox:SetWide( 200 )
		tdm_menu.TeamEntryEditBox:SetEnterAllowed( false )
		tdm_menu.TeamEntryEditBox:SetValue( team.GetName(CurrentTeamID) )
		
		-- Listing Box
		tdm_menu.TeamSpawnPoints = vgui.Create("DListView")
		tdm_menu.TeamSpawnPoints:SetParent(tdm_menu.TeamEditF)
		tdm_menu.TeamSpawnPoints:SetPos(15, 75)
		tdm_menu.TeamSpawnPoints:SetSize(200,75)
		tdm_menu.TeamSpawnPoints:AddColumn("ID")
		tdm_menu.TeamSpawnPoints:AddColumn("X")
		tdm_menu.TeamSpawnPoints:AddColumn("Y")
		tdm_menu.TeamSpawnPoints:AddColumn("Z")
		tdm_menu.TeamSpawnPoints:SetMultiSelect(false)
		for k, v in pairs(CustomSpawnPoints) do
			if v.TID == CurrentTeamID then
				tdm_menu.TeamSpawnPoints:AddLine(v.ID,v.XPos,v.YPos,v.ZPos)
			end
		end
		tdm_menu.TeamSpawnPoints.OnClickLine = function(_, line, WhatSelected)
			ID = line:GetValue(1)
			XPos = line:GetValue(2)
			YPos = line:GetValue(3)
			ZPos = line:GetValue(4)
		end
		
		-- Goto Button Team
		tdm_menu.TeamGotoButtClose = vgui.Create( "DButton", tdm_menu.TeamEditF )
		tdm_menu.TeamGotoButtClose:SetSize( 50, 20 )
		tdm_menu.TeamGotoButtClose:SetPos( 15, 155 )
		tdm_menu.TeamGotoButtClose:SetText( "Goto" )
		tdm_menu.TeamGotoButtClose.DoClick = function( button )
		if XPos == nil || YPos == nil || ZPos == nil then 
			Derma_Message("You haven't selected a pos to goto!", "[TDM] Error", "OK")
			surface.PlaySound( "apptdm/error.mp3" )
		return end
			net.Start("TDMGotoPos")
				net.WriteString(XPos)
				net.WriteString(YPos)
				net.WriteString(ZPos)
			net.SendToServer()
			tdm_menu.TeamEditF:Close()
			IsMenuOpenOrClosedEDITTeam = 0
			surface.PlaySound( "apptdm/success.mp3" )
		end
		
		-- Add Button Team
		tdm_menu.TeamSAddButtClose = vgui.Create( "DButton", tdm_menu.TeamEditF )
		tdm_menu.TeamSAddButtClose:SetSize( 50, 20 )
		tdm_menu.TeamSAddButtClose:SetPos( 165, 155 )
		tdm_menu.TeamSAddButtClose:SetText( "Add" )
		tdm_menu.TeamSAddButtClose.DoClick = function( button )
			net.Start("TDMAddPos")
				net.WriteString(CurrentTeamID)
			net.SendToServer()
			tdm_menu.TeamEditF:Close()
			IsMenuOpenOrClosedEDITTeam = 0
			surface.PlaySound( "apptdm/success.mp3" )
		end
		
		-- Remove Button Team
		tdm_menu.TeamSRemoveButtClose = vgui.Create( "DButton", tdm_menu.TeamEditF )
		tdm_menu.TeamSRemoveButtClose:SetSize( 50, 20 )
		tdm_menu.TeamSRemoveButtClose:SetPos( 90, 155 )
		tdm_menu.TeamSRemoveButtClose:SetText( "Remove" )
		tdm_menu.TeamSRemoveButtClose.DoClick = function( button )
		if XPos == nil || YPos == nil || ZPos == nil then 
			Derma_Message("You haven't selected a pos to delete!", "[TDM] Error", "OK")
			surface.PlaySound( "apptdm/error.mp3" )
		return end
			net.Start("TDMRemovePos")
				net.WriteString(CurrentTeamID)
				net.WriteString(ID)
			net.SendToServer()
			tdm_menu.TeamEditF:Close()
			IsMenuOpenOrClosedEDITTeam = 0
			surface.PlaySound( "apptdm/success.mp3" )
		end
		
		-- Color Wheel
		tdm_menu.ColorWheel2 = vgui.Create( "DColorMixer", tdm_menu.TeamEditF);
		tdm_menu.ColorWheel2:SetSize( 225, 200);
		tdm_menu.ColorWheel2:SetPos( 265, 30 );
		tdm_menu.ColorWheel2:SetColor(team.GetColor(CurrentTeamID))
		
		-- Close Button Team
		tdm_menu.TeamEditButtClose = vgui.Create( "DButton", tdm_menu.TeamEditF )
		tdm_menu.TeamEditButtClose:SetSize( 35, 20 )
		tdm_menu.TeamEditButtClose:SetPos( 460, 3 )
		tdm_menu.TeamEditButtClose:SetText( "Close" )
		tdm_menu.TeamEditButtClose.DoClick = function( button )
			tdm_menu.TeamEditF:Close()
			IsMenuOpenOrClosedEDITTeam = 0
		end
		
		-- Button Team
		tdm_menu.TeamEditButt = vgui.Create( "DButton", tdm_menu.TeamEditF )
		tdm_menu.TeamEditButt:SetSize( 200, 50 )
		tdm_menu.TeamEditButt:SetPos( 15, 180 )
		tdm_menu.TeamEditButt:SetText( "Edit" )
		tdm_menu.TeamEditButt.DoClick = function( button )
		if tdm_menu.TeamEntryEditBox:GetValue() == "" then
			Derma_Message("The team can't be empty, enter a valid team!", "[TDM] Error", "OK")
			surface.PlaySound( "apptdm/error.mp3" )
			return
		end
			for k, v in pairs(AddTeams2) do
				if tdm_menu.TeamEntryEditBox:GetValue() == v.tname then
					if k != CurrentTeamID then
						Derma_Message("The team can not be the same as another team in the list!", "[TDM] Error", "OK")
						surface.PlaySound( "apptdm/error.mp3" )
						return
					end
				end
			end
			
			net.Start("GetTeamListData229")
				net.WriteString(CurrentTeamID)
				net.WriteString(tdm_menu.TeamEntryEditBox:GetValue())
				net.WriteTable(tdm_menu.ColorWheel2:GetColor())
			net.SendToServer()
			
			tdm_menu.TeamEditF:Close()
			IsMenuOpenOrClosedEDITTeam = 0
			surface.PlaySound( "apptdm/success.mp3" )
			Derma_Message("You have successfully submitted the change!", "Team Deathmatch Gamemode", "OK")
		end
	end
end

-- Remove Teams
tdm_menu.TeamRemoveButton = vgui.Create( "DButton", tdm_menu.TabTwo )
tdm_menu.TeamRemoveButton:SetSize( 125, 20 )
tdm_menu.TeamRemoveButton:SetPos( 7, 135 )
tdm_menu.TeamRemoveButton:SetText( "Remove" )
tdm_menu.TeamRemoveButton.DoClick = function( button )
	if LocalPlayer():IsSuperAdmin() == false then
		IsMenuOpenOrClosedREMOVETeam = 0
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You are not an admin!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGE == 1 then
		IsMenuOpenOrClosedCHANGE = 0
		tdm_menu.ModelChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedEDITTeam == 1 then
		IsMenuOpenOrClosedEDITTeam = 0
		tdm_menu.TeamEditF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADD == 1 then
		IsMenuOpenOrClosedADD = 0
		tdm_menu.ModelAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVE == 1 then
		IsMenuOpenOrClosedREMOVE = 0
		tdm_menu.ModelRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDWep == 1 then
		IsMenuOpenOrClosedADDWep = 0
		tdm_menu.WeaponAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVEWep == 1 then
		IsMenuOpenOrClosedREMOVEWep = 0
		tdm_menu.WeaponRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGEWep == 1 then
		IsMenuOpenOrClosedCHANGEWep = 0
		tdm_menu.WeaponChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDTeam == 1 then
		IsMenuOpenOrClosedADDTeam = 0
		tdm_menu.TeamAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVETeam == 1 then
		IsMenuOpenOrClosedREMOVETeam = 0
		tdm_menu.TeamRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif SelectedTeamID == 0 then
	surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You have not selected a team to delete!", "[TDM] Error", "OK")
		return
	else
		
		
		IsMenuOpenOrClosedREMOVETeam = 1
		-- Entry Frame
		tdm_menu.TeamRemoveF = vgui.Create( "DFrame" )
		tdm_menu.TeamRemoveF:SetSize( 250, 100 )
		tdm_menu.TeamRemoveF:SetTitle("TEAM: ["..team.GetName(CurrentTeamID).."] Team Add")
		tdm_menu.TeamRemoveF:Center()
		tdm_menu.TeamRemoveF:ShowCloseButton( false )
		tdm_menu.TeamRemoveF:SetDraggable( false )
		tdm_menu.TeamRemoveF:MakePopup()

		tdm_menu.TeamRemoveLabel = vgui.Create("DLabel", tdm_menu.TeamRemoveF )
		tdm_menu.TeamRemoveLabel:SetPos(5,27)
		tdm_menu.TeamRemoveLabel:SetColor( Color( 0, 0, 0, 255 ) )
		tdm_menu.TeamRemoveLabel:SetText("This will delete the following team, are you sure:")
		tdm_menu.TeamRemoveLabel:SizeToContents()
		
		tdm_menu.TeamRemoveLabel2 = vgui.Create("DLabel", tdm_menu.TeamRemoveF )
		tdm_menu.TeamRemoveLabel2:SetPos(15,44)
		tdm_menu.TeamRemoveLabel2:SetColor( Color( 0, 0, 0, 255 ) )
		tdm_menu.TeamRemoveLabel2:SetText(SelectOneTeam)
		tdm_menu.TeamRemoveLabel2:SizeToContents()
		
		-- Close Button Team
		tdm_menu.TeamRemoveButtClose = vgui.Create( "DButton", tdm_menu.TeamRemoveF )
		tdm_menu.TeamRemoveButtClose:SetSize( 35, 20 )
		tdm_menu.TeamRemoveButtClose:SetPos( 210, 3 )
		tdm_menu.TeamRemoveButtClose:SetText( "Close" )
		tdm_menu.TeamRemoveButtClose.DoClick = function( button )
			tdm_menu.TeamRemoveF:Close()
			IsMenuOpenOrClosedREMOVETeam = 0
		end
		
		-- Button Team
		tdm_menu.TeamRemoveButt = vgui.Create( "DButton", tdm_menu.TeamRemoveF )
		tdm_menu.TeamRemoveButt:SetSize( 65, 25 )
		tdm_menu.TeamRemoveButt:SetPos( 90, 60 )
		tdm_menu.TeamRemoveButt:SetText( "Remove" )
		tdm_menu.TeamRemoveButt.DoClick = function( button )
			GetTeamListData42 = {}
			
			for k, v in pairs(AddTeams2) do
				GetTeamListData42 = k
			end	
			
			if GetTeamListData42 == 1 then
				Derma_Message("You can't delete the last team in the list", "[TDM] Error", "OK")
				surface.PlaySound( "apptdm/error.mp3" )
			return end

			net.Start("GetTeamListData56")
				net.WriteString(SelectOneTeamID)
			net.SendToServer()
			
			surface.PlaySound( "apptdm/success.mp3" )
			tdm_menu.TeamRemoveF:Close()
			IsMenuOpenOrClosedREMOVETeam = 0
			Derma_Message("You have successfully submitted the change!", "Team Deathmatch Gamemode", "OK")
		end
	end
end



-- Select Weapon
tdm_menu.WeaponsListing.OnClickLine = function(_, line, __)
SelectOneWeapon = line:GetValue(1)
SelectedWeaponIs = 1
end

-- Adds Weapons
tdm_menu.WeaponAddButton = vgui.Create( "DButton", tdm_menu.TabTwo )
tdm_menu.WeaponAddButton:SetSize( 201, 20 )
tdm_menu.WeaponAddButton:SetPos( 365, 111 )
tdm_menu.WeaponAddButton:SetText( "Add" )
tdm_menu.WeaponAddButton.DoClick = function( button )
	if LocalPlayer():IsSuperAdmin() == false then
		IsMenuOpenOrClosedADDWep = 0
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You are not an admin!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGE == 1 then
		IsMenuOpenOrClosedCHANGE = 0
		tdm_menu.ModelChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADD == 1 then
		IsMenuOpenOrClosedADD = 0
		tdm_menu.ModelAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedEDITTeam == 1 then
		IsMenuOpenOrClosedEDITTeam = 0
		tdm_menu.TeamEditF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVE == 1 then
		IsMenuOpenOrClosedREMOVE = 0
		tdm_menu.ModelRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDWep == 1 then
		IsMenuOpenOrClosedADDWep = 0
		tdm_menu.WeaponAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVEWep == 1 then
		IsMenuOpenOrClosedREMOVEWep = 0
		tdm_menu.WeaponRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGEWep == 1 then
		IsMenuOpenOrClosedCHANGEWep = 0
		tdm_menu.WeaponChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDTeam == 1 then
		IsMenuOpenOrClosedADDTeam = 0
		tdm_menu.TeamAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVETeam == 1 then
		IsMenuOpenOrClosedREMOVETeam = 0
		tdm_menu.TeamRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif SelectedTeamID == 0 then
	surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You have not selected a team to add a weapon to!", "[TDM] Error", "OK")	
		return
	else
		
		
		Gmodweapons = {}
		Gmodweapons = {"weapon_para","weapon_crowbar","weapon_stunstick","weapon_physcannon","weapon_physgun","weapon_pistol","weapon_357","weapon_smg1","weapon_ar2","weapon_shotgun","weapon_crossbow",  "weapon_frag", "weapon_rpg", "weapon_slam", "weapon_bugbait", "gmod_camera"}
		
		IsMenuOpenOrClosedADDWep = 1
		-- Entry Frame
		tdm_menu.WeaponAddF = vgui.Create( "DFrame" )
		tdm_menu.WeaponAddF:SetSize( 250, 100 )
		tdm_menu.WeaponAddF:SetTitle("TEAM: ["..team.GetName(CurrentTeamID).."] Weapon Add")
		tdm_menu.WeaponAddF:Center()
		tdm_menu.WeaponAddF:ShowCloseButton( false )
		tdm_menu.WeaponAddF:SetDraggable( false )
		tdm_menu.WeaponAddF:MakePopup()

		-- The Listing Box
		NewWepIconFrame = 0
		CkIcF3 = 0
		tdm_menu.WepEntryAddBox = vgui.Create("DButton", tdm_menu.WeaponAddF)
		tdm_menu.WepEntryAddBox:SetText( "Weapon Selector:" )
		tdm_menu.WepEntryAddBox:SetPos( 25,30 )
		tdm_menu.WepEntryAddBox:SetTall( 25 )
		tdm_menu.WepEntryAddBox:SetWide( 200 )
		tdm_menu.WepEntryAddBox.DoClick = function ( btn )
		tdm_menu.WepButtonOptions = DermaMenu()
		for k,v in pairs(weapons.GetList()) do
		CheckBase = string.Explode("_",v.ClassName)
		CheckBase = string.Implode(" ",CheckBase)
			if !string.find(CheckBase, "base") then
				if !string.find(v.ClassName, "flechette_gun") then
					tdm_menu.WepButtonOptions:AddOption(v.ClassName, function()  
						tdm_menu.WepEntryAddBox:SetText( v.ClassName )
						
						if CkIcF3 == 1 then
							tdm_menu.iconframenw:Close()
						end
						AddNewWeap = v.ClassName
						
						tdm_menu.iconframenw = vgui.Create( "DFrame" )
						tdm_menu.iconframenw:SetPos( 300,250 )
						tdm_menu.iconframenw:SetSize( 200, 250 )
						tdm_menu.iconframenw:SetTitle( v.ClassName )
						tdm_menu.iconframenw:SetVisible( true )
						tdm_menu.iconframenw:SetDraggable( true )
						tdm_menu.iconframenw:ShowCloseButton( false )
						tdm_menu.iconframenw:MakePopup()
						
						tdm_menu.wnewmicon = vgui.Create( "DModelPanel", tdm_menu.iconframenw )
						tdm_menu.wnewmicon:SetModel( v.WorldModel )
						tdm_menu.wnewmicon:SetPos(-120, -70)
						tdm_menu.wnewmicon:SetSize( 450, 450 )
						tdm_menu.wnewmicon:SetCamPos( Vector( 50, 100, 0 ) )
						tdm_menu.wnewmicon:SetLookAt( Vector( 0, 0, 0 ) )
						
						tdm_menu.ModelFAddButtClose = vgui.Create( "DButton", tdm_menu.iconframenw )
						tdm_menu.ModelFAddButtClose:SetSize( 85, 23 )
						tdm_menu.ModelFAddButtClose:SetPos( 55, 220 )
						tdm_menu.ModelFAddButtClose:SetText( "Close" )
						tdm_menu.ModelFAddButtClose.DoClick = function( button )
							tdm_menu.iconframenw:Close()
							NewWepIconFrame = 1
							CkIcF3 = 0
						return end
						NewWepIconFrame = 0
						CkIcF3 = 1
					end )
				end
			end
		end	
		tdm_menu.WepButtonOptions:Open()
		end	
		
		-- Close Button
		tdm_menu.WeapAddButtClose = vgui.Create( "DButton", tdm_menu.WeaponAddF )
		tdm_menu.WeapAddButtClose:SetSize( 35, 20 )
		tdm_menu.WeapAddButtClose:SetPos( 210, 3 )
		tdm_menu.WeapAddButtClose:SetText( "Close" )
		tdm_menu.WeapAddButtClose.DoClick = function( button )
			tdm_menu.WeaponAddF:Close()
			IsMenuOpenOrClosedADDWep = 0
			if NewWepIconFrame == 0 then
				if CkIcF3 == 0 then return end
				tdm_menu.iconframenw:Close()
			end
		end
		
		-- Button
		tdm_menu.WeaponAddButt = vgui.Create( "DButton", tdm_menu.WeaponAddF )
		tdm_menu.WeaponAddButt:SetSize( 65, 25 )
		tdm_menu.WeaponAddButt:SetPos( 90, 60 )
		tdm_menu.WeaponAddButt:SetText( "Add" )
		tdm_menu.WeaponAddButt.DoClick = function( button )
		GetWeaponListData55 = {}
		if AddNewWeap == "" || AddNewWeap == nil then
			Derma_Message("The weapon can't be empty, enter a valid weapon!", "[TDM] Error", "OK")
			surface.PlaySound( "apptdm/error.mp3" )
			return
		elseif string.find(AddNewWeap, "base") then
			Derma_Message("The weapon can't be a base, enter a valid weapon!", "[TDM] Error", "OK")
			surface.PlaySound( "apptdm/error.mp3" )
			return
		end
			for k, v in pairs(GetWeaponsListData) do
				if AddNewWeap == v.Weapons then
					Derma_Message("The weapon can not be the same as another weapon in the list!", "[TDM] Error", "OK")
					surface.PlaySound( "apptdm/error.mp3" )
					return
				else
				GetWeaponListData55[k] = {
				Weapons = v.Weapons
				}
				GetLastAddWeapon = k + 1
				end
			end
			
			GetModelListDData26 = {}
			GetModelListDData26[GetLastAddWeapon] = {
			Weapons = AddNewWeap
			}
		
			table.Add(GetWeaponListData55,GetModelListDData26)
			
			net.Start("GetWeaponListData55")
				net.WriteString(CurrentTeamID)
				net.WriteTable(GetWeaponListData55)
			net.SendToServer()
			tdm_menu.WeaponAddF:Close()
			IsMenuOpenOrClosedADDWep = 0
			surface.PlaySound( "apptdm/success.mp3" )
			Derma_Message("You have successfully submitted the change!", "Team Deathmatch Gamemode", "OK")
			if NewWepIconFrame == 0 then
				if CkIcF3 == 0 then return end
				tdm_menu.iconframenw:Close()
			end
		end
	end
end


-- Removes Weapon
tdm_menu.WeaponRemoveBut = vgui.Create( "DButton", tdm_menu.TabTwo )
tdm_menu.WeaponRemoveBut:SetSize( 201, 20 )
tdm_menu.WeaponRemoveBut:SetPos( 365, 135 )
tdm_menu.WeaponRemoveBut:SetText( "Remove" )
tdm_menu.WeaponRemoveBut.DoClick = function( button )
	if LocalPlayer():IsSuperAdmin() == false then
		IsMenuOpenOrClosedREMOVEWep = 0
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You are not an admin!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGE == 1 then
		IsMenuOpenOrClosedCHANGE = 0
		tdm_menu.ModelChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADD == 1 then
		IsMenuOpenOrClosedADD = 0
		tdm_menu.ModelAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedEDITTeam == 1 then
		IsMenuOpenOrClosedEDITTeam = 0
		tdm_menu.TeamEditF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVE == 1 then
		IsMenuOpenOrClosedREMOVE = 0
		tdm_menu.ModelRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDWep == 1 then
		IsMenuOpenOrClosedADDWep = 0
		tdm_menu.WeaponAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVEWep == 1 then
		IsMenuOpenOrClosedREMOVEWep = 0
		tdm_menu.WeaponRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGEWep == 1 then
		IsMenuOpenOrClosedCHANGEWep = 0
		tdm_menu.WeaponChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDTeam == 1 then
		IsMenuOpenOrClosedADDTeam = 0
		tdm_menu.TeamAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVETeam == 1 then
		IsMenuOpenOrClosedREMOVETeam = 0
		tdm_menu.TeamRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif SelectedWeaponIs == 0 then
	surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You have not selected a weapon to remove!", "[TDM] Error", "OK")	
		return
	else
	
		
		IsMenuOpenOrClosedREMOVEWep = 1
		-- Entry Frame
		tdm_menu.WeaponRemoveF = vgui.Create( "DFrame" )
		tdm_menu.WeaponRemoveF:SetSize( 260, 100 )
		tdm_menu.WeaponRemoveF:SetTitle("TEAM: ["..team.GetName(CurrentTeamID).."] Weapon Remove")
		tdm_menu.WeaponRemoveF:Center()
		tdm_menu.WeaponRemoveF:ShowCloseButton( false )
		tdm_menu.WeaponRemoveF:SetDraggable( false )
		tdm_menu.WeaponRemoveF:MakePopup()
		
		tdm_menu.WeaponRemoveLabel = vgui.Create("DLabel", tdm_menu.WeaponRemoveF )
		tdm_menu.WeaponRemoveLabel:SetPos(5,27)
		tdm_menu.WeaponRemoveLabel:SetColor( Color( 0, 0, 0, 255 ) )
		tdm_menu.WeaponRemoveLabel:SetText("This will delete the following weapons, are you sure:")
		tdm_menu.WeaponRemoveLabel:SizeToContents()
		
		tdm_menu.WeaponRemoveLabel2 = vgui.Create("DLabel", tdm_menu.WeaponRemoveF )
		tdm_menu.WeaponRemoveLabel2:SetPos(15,44)
		tdm_menu.WeaponRemoveLabel2:SetColor( Color( 0, 0, 0, 255 ) )
		tdm_menu.WeaponRemoveLabel2:SetText(SelectOneWeapon)
		tdm_menu.WeaponRemoveLabel2:SizeToContents()
		
		-- Close Button
		tdm_menu.WeaponRemoveButtClose = vgui.Create( "DButton", tdm_menu.WeaponRemoveF )
		tdm_menu.WeaponRemoveButtClose:SetSize( 35, 20 )
		tdm_menu.WeaponRemoveButtClose:SetPos( 210, 3 )
		tdm_menu.WeaponRemoveButtClose:SetText( "Close" )
		tdm_menu.WeaponRemoveButtClose.DoClick = function( button )
			tdm_menu.WeaponRemoveF:Close()
			IsMenuOpenOrClosedREMOVEWep = 0
		end
		
		-- Button
		tdm_menu.WeaponRemoveButt = vgui.Create( "DButton", tdm_menu.WeaponRemoveF )
		tdm_menu.WeaponRemoveButt:SetSize( 65, 25 )
		tdm_menu.WeaponRemoveButt:SetPos( 90, 60 )
		tdm_menu.WeaponRemoveButt:SetText( "Delete" )
		tdm_menu.WeaponRemoveButt.DoClick = function( button )
		GetWeaponListData55 = {}
		GetModelListData58 = {}
			for k, v in pairs(GetWeaponsListData) do
				GetModelListData58 = k
				if v.Weapons != SelectOneWeapon then
					GetWeaponListData55[k] = {
					Weapons = v.Weapons
					}
				end
			end	
			if GetModelListData58 == 1 then
			Derma_Message("You can't delete the last model in this team", "[TDM] Error", "OK")
			surface.PlaySound( "apptdm/error.mp3" )
			return end
			net.Start("GetWeaponListData55")
				net.WriteString(CurrentTeamID)
				net.WriteTable(GetWeaponListData55)
			net.SendToServer()
			
			surface.PlaySound( "apptdm/success.mp3" )
			tdm_menu.WeaponRemoveF:Close()
			IsMenuOpenOrClosedREMOVEWep = 0
			Derma_Message("You have successfully submitted the change!", "Team Deathmatch Gamemode", "OK")
		end
	end
end


-- Change Weapon
tdm_menu.WeaponChangeBut = vgui.Create( "DButton", tdm_menu.TabTwo )
tdm_menu.WeaponChangeBut:SetSize( 201, 20 )
tdm_menu.WeaponChangeBut:SetPos( 365, 159 )
tdm_menu.WeaponChangeBut:SetText( "Change" )
tdm_menu.WeaponChangeBut.DoClick = function( button )
	if LocalPlayer():IsSuperAdmin() == false then
		IsMenuOpenOrClosedCHANGEWep = 0
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You are not an admin!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGE == 1 then
		IsMenuOpenOrClosedCHANGE = 0
		tdm_menu.ModelChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADD == 1 then
		IsMenuOpenOrClosedADD = 0
		tdm_menu.ModelAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedEDITTeam == 1 then
		IsMenuOpenOrClosedEDITTeam = 0
		tdm_menu.TeamEditF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVE == 1 then
		IsMenuOpenOrClosedREMOVE = 0
		tdm_menu.ModelRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDWep == 1 then
		IsMenuOpenOrClosedADDWep = 0
		tdm_menu.WeaponAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVEWep == 1 then
		IsMenuOpenOrClosedREMOVEWep = 0
		tdm_menu.WeaponRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGEWep == 1 then
		IsMenuOpenOrClosedCHANGEWep = 0
		tdm_menu.WeaponChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDTeam == 1 then
		IsMenuOpenOrClosedADDTeam = 0
		tdm_menu.TeamAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVETeam == 1 then
		IsMenuOpenOrClosedREMOVETeam = 0
		tdm_menu.TeamRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif SelectedTeamID == 0 then
	surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You have not selected a team to be able to edit a weapon!", "[TDM] Error", "OK")	
		return
	elseif SelectedWeaponIs == 0 then
	surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You have not selected a weapon to edit!", "[TDM] Error", "OK")
		return
	else
	
		Gmodweapons = {}
		Gmodweapons = {"weapon_para","weapon_crowbar","weapon_stunstick","weapon_physcannon","weapon_physgun","weapon_pistol","weapon_357","weapon_smg1","weapon_ar2","weapon_shotgun","weapon_crossbow",  "weapon_frag", "weapon_rpg", "weapon_slam", "weapon_bugbait", "gmod_camera"}
		IsMenuOpenOrClosedCHANGEWep = 1
		-- Entry Frame
		tdm_menu.WeaponChangeF = vgui.Create( "DFrame" )
		tdm_menu.WeaponChangeF:SetSize( 250, 100 )
		tdm_menu.WeaponChangeF:SetTitle("TEAM: ["..team.GetName(CurrentTeamID).."] Model Change")
		tdm_menu.WeaponChangeF:Center()
		tdm_menu.WeaponChangeF:ShowCloseButton( false )
		tdm_menu.WeaponChangeF:SetDraggable( false )
		tdm_menu.WeaponChangeF:MakePopup()
		
		-- The Listing Box
		ChangeWepIconFrame = 0
		CkIcF55 = 0
		tdm_menu.WeaponEntryChangeBox = vgui.Create("DButton", tdm_menu.WeaponChangeF)
		tdm_menu.WeaponEntryChangeBox:SetText( SelectOneWeapon )
		tdm_menu.WeaponEntryChangeBox:SetPos( 25,30 )
		tdm_menu.WeaponEntryChangeBox:SetTall( 25 )
		tdm_menu.WeaponEntryChangeBox:SetWide( 200 )
		tdm_menu.WeaponEntryChangeBox.DoClick = function ( btn )
		tdm_menu.WepButtonOptions2 = DermaMenu()
		for k,v in pairs(weapons.GetList()) do
		CheckBase = string.Explode("_",v.ClassName)
		CheckBase = string.Implode(" ",CheckBase)
			if !string.find(CheckBase, "base") then
				if !string.find(v.ClassName, "flechette_gun") then
					tdm_menu.WepButtonOptions2:AddOption(v.ClassName, function()  
						tdm_menu.WeaponEntryChangeBox:SetText( v.ClassName )
						
						if CkIcF55 == 1 then
							tdm_menu.iconframenw2s:Close()
						end
						ChangeNewWeap = v.ClassName
						
						tdm_menu.iconframenw2s = vgui.Create( "DFrame" )
						tdm_menu.iconframenw2s:SetPos( 300,250 )
						tdm_menu.iconframenw2s:SetSize( 200, 250 )
						tdm_menu.iconframenw2s:SetTitle( v.ClassName )
						tdm_menu.iconframenw2s:SetVisible( true )
						tdm_menu.iconframenw2s:SetDraggable( true )
						tdm_menu.iconframenw2s:ShowCloseButton( false )
						tdm_menu.iconframenw2s:MakePopup()
						
						tdm_menu.wnewmicon2s = vgui.Create( "DModelPanel", tdm_menu.iconframenw2s )
						tdm_menu.wnewmicon2s:SetModel( v.WorldModel )
						tdm_menu.wnewmicon2s:SetPos(-120, -70)
						tdm_menu.wnewmicon2s:SetSize( 450, 450 )
						tdm_menu.wnewmicon2s:SetCamPos( Vector( 50, 100, 0 ) )
						tdm_menu.wnewmicon2s:SetLookAt( Vector( 0, 0, 0 ) )
						
						tdm_menu.ModelFAddButtClose2s = vgui.Create( "DButton", tdm_menu.iconframenw2s )
						tdm_menu.ModelFAddButtClose2s:SetSize( 85, 23 )
						tdm_menu.ModelFAddButtClose2s:SetPos( 55, 220 )
						tdm_menu.ModelFAddButtClose2s:SetText( "Close" )
						tdm_menu.ModelFAddButtClose2s.DoClick = function( button )
							tdm_menu.iconframenw2s:Close()
							ChangeWepIconFrame = 1
							CkIcF55 = 0
						return end
						ChangeWepIconFrame = 0
						CkIcF55 = 1
					end )
				end
			end
		end	
		tdm_menu.WepButtonOptions2:Open()
		end	

		
		-- Close Button
		tdm_menu.WeaponChangeAddButClose = vgui.Create( "DButton", tdm_menu.WeaponChangeF )
		tdm_menu.WeaponChangeAddButClose:SetSize( 35, 20 )
		tdm_menu.WeaponChangeAddButClose:SetPos( 210, 3 )
		tdm_menu.WeaponChangeAddButClose:SetText( "Close" )
		tdm_menu.WeaponChangeAddButClose.DoClick = function( button )
			tdm_menu.WeaponChangeF:Close()
			IsMenuOpenOrClosedCHANGEWep = 0
			if ChangeWepIconFrame == 0 then
				if CkIcF55 == 0 then return end
				tdm_menu.iconframenw2s:Close()
			end
		end
		
		-- Button
		tdm_menu.WeaponChangeAddBut = vgui.Create( "DButton", tdm_menu.WeaponChangeF )
		tdm_menu.WeaponChangeAddBut:SetSize( 65, 25 )
		tdm_menu.WeaponChangeAddBut:SetPos( 90, 60 )
		tdm_menu.WeaponChangeAddBut:SetText( "Change" )
		tdm_menu.WeaponChangeAddBut.DoClick = function( button )
		GetWeaponListData55 = {}
		if ChangeNewWeap == "" || ChangeNewWeap == nil then
			surface.PlaySound( "apptdm/error.mp3" )
			Derma_Message("The model can't be empty, enter a valid model!", "[TDM] Error", "OK")
			return
		elseif string.find(ChangeNewWeap, "base") then
			surface.PlaySound( "apptdm/error.mp3" )
			Derma_Message("The weapon can't be a base, enter a valid weapon!", "[TDM] Error", "OK")
			return
		end
			for k, v in pairs(GetWeaponsListData) do
				if ChangeNewWeap == v.Weapons then
					surface.PlaySound( "apptdm/error.mp3" )
					Derma_Message("The weapon can not be the same as another weapon in the list!", "[TDM] Error", "OK")
					return
				else
					if v.Weapons == SelectOneWeapon then
						v.Weapons = string.gsub(SelectOneWeapon,v.Weapons,ChangeNewWeap)
					end
					
						GetWeaponListData55[k] = {
						Weapons = v.Weapons
						}
				end
			end
			net.Start("GetWeaponListData55")
				net.WriteString(CurrentTeamID)
				net.WriteTable(GetWeaponListData55)
			net.SendToServer()
				
			surface.PlaySound( "apptdm/success.mp3" )
			tdm_menu.WeaponChangeF:Close()
			IsMenuOpenOrClosedCHANGEWep = 0
			Derma_Message("You have successfully submitted the change!", "Team Deathmatch Gamemode", "OK")
			if ChangeWepIconFrame == 0 then
				if CkIcF55 == 0 then return end
				tdm_menu.iconframenw2s:Close()
			end
		end
	end
end



-- Check Model Listing
tdm_menu.ModelListing.OnClickLine = function(_, line, __)
SelectOneModel = line:GetValue(1)
SelectedModelIs = 1
end

-- Adds Model
tdm_menu.ModelAddBut = vgui.Create( "DButton", tdm_menu.TabTwo )
tdm_menu.ModelAddBut:SetSize( 220, 20 )
tdm_menu.ModelAddBut:SetPos( 139, 111 )
tdm_menu.ModelAddBut:SetText( "Add" )
tdm_menu.ModelAddBut.DoClick = function( button )
	if LocalPlayer():IsSuperAdmin() == false then
		IsMenuOpenOrClosedADD = 0
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You are not an admin!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGE == 1 then
		IsMenuOpenOrClosedCHANGE = 0
		tdm_menu.ModelChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADD == 1 then
		IsMenuOpenOrClosedADD = 0
		tdm_menu.ModelAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedEDITTeam == 1 then
		IsMenuOpenOrClosedEDITTeam = 0
		tdm_menu.TeamEditF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVE == 1 then
		IsMenuOpenOrClosedREMOVE = 0
		tdm_menu.ModelRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDWep == 1 then
		IsMenuOpenOrClosedADDWep = 0
		tdm_menu.WeaponAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVEWep == 1 then
		IsMenuOpenOrClosedREMOVEWep = 0
		tdm_menu.WeaponRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGEWep == 1 then
		IsMenuOpenOrClosedCHANGEWep = 0
		tdm_menu.WeaponChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDTeam == 1 then
		IsMenuOpenOrClosedADDTeam = 0
		tdm_menu.TeamAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVETeam == 1 then
		IsMenuOpenOrClosedREMOVETeam = 0
		tdm_menu.TeamRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif SelectedTeamID == 0 then
	surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You have not selected a team to add a model to!", "[TDM] Error", "OK")	
		return
	else
		
		
		IsMenuOpenOrClosedADD = 1
		-- Entry Frame
		tdm_menu.ModelAddF = vgui.Create( "DFrame" )
		tdm_menu.ModelAddF:SetSize( 250, 100 )
		tdm_menu.ModelAddF:SetTitle("TEAM: ["..team.GetName(CurrentTeamID).."] Model Add")
		tdm_menu.ModelAddF:Center()
		tdm_menu.ModelAddF:ShowCloseButton( false )
		tdm_menu.ModelAddF:SetDraggable( false )
		tdm_menu.ModelAddF:MakePopup()

		-- Entry Box Model
		tdm_menu.EntryAddBox = vgui.Create( "DTextEntry", tdm_menu.ModelAddF)
		tdm_menu.EntryAddBox:SetPos( 25,30 )
		tdm_menu.EntryAddBox:SetTall( 25 )
		tdm_menu.EntryAddBox:SetWide( 200 )
		tdm_menu.EntryAddBox:SetEnterAllowed( false )
		tdm_menu.EntryAddBox:SetValue( "models/player/Group01/male_01.mdl" )
		
		
		-- The Listing Box
		NewModelIconFrame = 0
		CkIcF2 = 0
		tdm_menu.ModelEntryAddBox = vgui.Create("DButton", tdm_menu.ModelAddF)
		tdm_menu.ModelEntryAddBox:SetText( "Model Selector:" )
		tdm_menu.ModelEntryAddBox:SetPos( 25,30 )
		tdm_menu.ModelEntryAddBox:SetTall( 25 )
		tdm_menu.ModelEntryAddBox:SetWide( 200 )
		tdm_menu.ModelEntryAddBox.DoClick = function ( btn )
			tdm_menu.ModelButtonOptions = DermaMenu()
			for k,v in pairs(player_manager.AllValidModels()) do
				tdm_menu.ModelButtonOptions:AddOption(v, function() 
					tdm_menu.ModelEntryAddBox:SetText( v )
						if CkIcF2 == 1 then
							tdm_menu.iconframenm:Close()
						end
						AddNewModel = v
						tdm_menu.iconframenm = vgui.Create( "DFrame" )
						tdm_menu.iconframenm:SetPos( 400,250 )
						tdm_menu.iconframenm:SetSize( 200, 250 )
						tdm_menu.iconframenm:SetTitle( AddNewModel )
						tdm_menu.iconframenm:SetVisible( true )
						tdm_menu.iconframenm:SetDraggable( true )
						tdm_menu.iconframenm:ShowCloseButton( false )
						tdm_menu.iconframenm:MakePopup()
						
						tdm_menu.newmicon = vgui.Create( "DModelPanel", tdm_menu.iconframenm )
						tdm_menu.newmicon:SetModel( AddNewModel )
						tdm_menu.newmicon:SetPos(-80, 20)
						tdm_menu.newmicon:SetSize( 350, 350 )
						tdm_menu.newmicon:SetCamPos( Vector( 50, 100, 120 ) )
						tdm_menu.newmicon:SetLookAt( Vector( 0, 0, 0 ) )
						
						tdm_menu.ModelFAddButtClose = vgui.Create( "DButton", tdm_menu.iconframenm )
						tdm_menu.ModelFAddButtClose:SetSize( 85, 23 )
						tdm_menu.ModelFAddButtClose:SetPos( 55, 220 )
						tdm_menu.ModelFAddButtClose:SetText( "Close" )
						tdm_menu.ModelFAddButtClose.DoClick = function( button )
							tdm_menu.iconframenm:Close()
							NewModelIconFrame = 1
							CkIcF2 = 0
						return end
						NewModelIconFrame = 0
						CkIcF2 = 1
				end)
			end	
		tdm_menu.ModelButtonOptions:Open()
		end	
		
		-- Close Button
		tdm_menu.ModelAddButtClose = vgui.Create( "DButton", tdm_menu.ModelAddF )
		tdm_menu.ModelAddButtClose:SetSize( 35, 20 )
		tdm_menu.ModelAddButtClose:SetPos( 210, 3 )
		tdm_menu.ModelAddButtClose:SetText( "Close" )
		tdm_menu.ModelAddButtClose.DoClick = function( button )
			tdm_menu.ModelAddF:Close()
			IsMenuOpenOrClosedADD = 0
			if NewModelIconFrame == 0 then
				if CkIcF2 == 0 then return end
				tdm_menu.iconframenm:Close()
			end
		end
		
		-- Button
		tdm_menu.ModelAddButt = vgui.Create( "DButton", tdm_menu.ModelAddF )
		tdm_menu.ModelAddButt:SetSize( 65, 25 )
		tdm_menu.ModelAddButt:SetPos( 90, 60 )
		tdm_menu.ModelAddButt:SetText( "Add" )
		tdm_menu.ModelAddButt.DoClick = function( button )
		GetModelListData2 = {}
		if AddNewModel == "" || AddNewModel == nil then
			Derma_Message("The model can't be empty, enter a valid model!", "[TDM] Error", "OK")
			surface.PlaySound( "apptdm/error.mp3" )
			return
		end
			for k, v in pairs(GetModelListData) do
				if AddNewModel == v.Models then
					Derma_Message("The model can not be the same as another model in the list!", "[TDM] Error", "OK")
					surface.PlaySound( "apptdm/error.mp3" )
					return
				else
				GetModelListData2[k] = {
				Models = v.Models
				}
				GetLastAddModel = k + 1
				end
			end
			
			GetModelListDData2 = {}
			GetModelListDData2[GetLastAddModel] = {
			Models = AddNewModel
			}
		
			table.Add(GetModelListData2,GetModelListDData2)
			
			net.Start("GetModelListData2")
				net.WriteString(CurrentTeamID)
				net.WriteTable(GetModelListData2)
			net.SendToServer()
		
			surface.PlaySound( "apptdm/success.mp3" )
			tdm_menu.ModelAddF:Close()
			Derma_Message("You have successfully submitted the change!", "Team Deathmatch Gamemode", "OK")
			IsMenuOpenOrClosedADD = 0
			if NewModelIconFrame == 0 then
				if CkIcF2 == 0 then return end
				tdm_menu.iconframenm:Close()
			end
		end
	end
end

-- Removes Model
tdm_menu.ModelRemoveBut = vgui.Create( "DButton", tdm_menu.TabTwo )
tdm_menu.ModelRemoveBut:SetSize( 220, 20 )
tdm_menu.ModelRemoveBut:SetPos( 139, 135 )
tdm_menu.ModelRemoveBut:SetText( "Remove" )
tdm_menu.ModelRemoveBut.DoClick = function( button )
	if LocalPlayer():IsSuperAdmin() == false then
		IsMenuOpenOrClosedREMOVE = 0
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You are not an admin!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGE == 1 then
		IsMenuOpenOrClosedCHANGE = 0
		tdm_menu.ModelChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADD == 1 then
		IsMenuOpenOrClosedADD = 0
		tdm_menu.ModelAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedEDITTeam == 1 then
		IsMenuOpenOrClosedEDITTeam = 0
		tdm_menu.TeamEditF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVE == 1 then
		IsMenuOpenOrClosedREMOVE = 0
		tdm_menu.ModelRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDWep == 1 then
		IsMenuOpenOrClosedADDWep = 0
		tdm_menu.WeaponAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVEWep == 1 then
		IsMenuOpenOrClosedREMOVEWep = 0
		tdm_menu.WeaponRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGEWep == 1 then
		IsMenuOpenOrClosedCHANGEWep = 0
		tdm_menu.WeaponChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDTeam == 1 then
		IsMenuOpenOrClosedADDTeam = 0
		tdm_menu.TeamAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVETeam == 1 then
		IsMenuOpenOrClosedREMOVETeam = 0
		tdm_menu.TeamRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif SelectedModelIs == 0 then
	surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You have not selected a model to remove!", "[TDM] Error", "OK")
		return
	else
	
		
		IsMenuOpenOrClosedREMOVE = 1
		-- Entry Frame
		tdm_menu.ModelRemoveF = vgui.Create( "DFrame" )
		tdm_menu.ModelRemoveF:SetSize( 250, 100 )
		tdm_menu.ModelRemoveF:SetTitle("TEAM: ["..team.GetName(CurrentTeamID).."] Model Remove")
		tdm_menu.ModelRemoveF:Center()
		tdm_menu.ModelRemoveF:ShowCloseButton( false )
		tdm_menu.ModelRemoveF:SetDraggable( false )
		tdm_menu.ModelRemoveF:MakePopup()
		
		tdm_menu.ModelRemoveLabel = vgui.Create("DLabel", tdm_menu.ModelRemoveF )
		tdm_menu.ModelRemoveLabel:SetPos(5,27)
		tdm_menu.ModelRemoveLabel:SetColor( Color( 0, 0, 0, 255 ) )
		tdm_menu.ModelRemoveLabel:SetText("This will delete the following model, are you sure:")
		tdm_menu.ModelRemoveLabel:SizeToContents()
		
		tdm_menu.ModelRemoveLabel2 = vgui.Create("DLabel", tdm_menu.ModelRemoveF )
		tdm_menu.ModelRemoveLabel2:SetPos(15,44)
		tdm_menu.ModelRemoveLabel2:SetColor( Color( 0, 0, 0, 255 ) )
		tdm_menu.ModelRemoveLabel2:SetText(SelectOneModel)
		tdm_menu.ModelRemoveLabel2:SizeToContents()
		
		-- Close Button
		tdm_menu.ModelRemoveButtClose = vgui.Create( "DButton", tdm_menu.ModelRemoveF )
		tdm_menu.ModelRemoveButtClose:SetSize( 35, 20 )
		tdm_menu.ModelRemoveButtClose:SetPos( 210, 3 )
		tdm_menu.ModelRemoveButtClose:SetText( "Close" )
		tdm_menu.ModelRemoveButtClose.DoClick = function( button )
			tdm_menu.ModelRemoveF:Close()
			IsMenuOpenOrClosedREMOVE = 0
		end
		
		-- Button
		tdm_menu.ModelRemoveButt = vgui.Create( "DButton", tdm_menu.ModelRemoveF )
		tdm_menu.ModelRemoveButt:SetSize( 65, 25 )
		tdm_menu.ModelRemoveButt:SetPos( 90, 60 )
		tdm_menu.ModelRemoveButt:SetText( "Delete" )
		tdm_menu.ModelRemoveButt.DoClick = function( button )
		GetModelListData2 = {}
		GetModelListData33 = {}
			for k, v in pairs(GetModelListData) do
				GetModelListData33 = k
				if v.Models != SelectOneModel then
					GetModelListData2[k] = {
					Models = v.Models
					}
				end
			end	
			if GetModelListData33 == 1 then
			Derma_Message("You can't delete the last model in this team", "[TDM] Error", "OK")
			surface.PlaySound( "apptdm/error.mp3" )
			return end
			net.Start("GetModelListData2")
				net.WriteString(CurrentTeamID)
				net.WriteTable(GetModelListData2)
			net.SendToServer()
			
			surface.PlaySound( "apptdm/success.mp3" )
			tdm_menu.ModelRemoveF:Close()
			IsMenuOpenOrClosedREMOVE = 0
			Derma_Message("You have successfully submitted the change!", "Team Deathmatch Gamemode", "OK")
		end
	end
end

-- Change Model
tdm_menu.ChangeRemoveBut = vgui.Create( "DButton", tdm_menu.TabTwo )
tdm_menu.ChangeRemoveBut:SetSize( 220, 20 )
tdm_menu.ChangeRemoveBut:SetPos( 139, 159 )
tdm_menu.ChangeRemoveBut:SetText( "Change" )
tdm_menu.ChangeRemoveBut.DoClick = function( button )
	if LocalPlayer():IsSuperAdmin() == false then
		IsMenuOpenOrClosedCHANGE = 0
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You are not an admin!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGE == 1 then
		IsMenuOpenOrClosedCHANGE = 0
		surface.PlaySound( "apptdm/error.mp3" )
		tdm_menu.ModelChangeF:Close()
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADD == 1 then
		IsMenuOpenOrClosedADD = 0
		tdm_menu.ModelAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedEDITTeam == 1 then
		IsMenuOpenOrClosedEDITTeam = 0
		tdm_menu.TeamEditF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVE == 1 then
		IsMenuOpenOrClosedREMOVE = 0
		tdm_menu.ModelRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDWep == 1 then
		IsMenuOpenOrClosedADDWep = 0
		tdm_menu.WeaponAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVEWep == 1 then
		IsMenuOpenOrClosedREMOVEWep = 0
		tdm_menu.WeaponRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedCHANGEWep == 1 then
		IsMenuOpenOrClosedCHANGEWep = 0
		tdm_menu.WeaponChangeF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedADDTeam == 1 then
		IsMenuOpenOrClosedADDTeam = 0
		tdm_menu.TeamAddF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif IsMenuOpenOrClosedREMOVETeam == 1 then
		IsMenuOpenOrClosedREMOVETeam = 0
		tdm_menu.TeamRemoveF:Close()
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
		return
	elseif SelectedTeamID == 0 then		
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You have not selected a team to be able to edit a model!", "[TDM] Error", "OK")
		return
	elseif SelectedModelIs == 0 then
		surface.PlaySound( "apptdm/error.mp3" )
		Derma_Message("You have not selected a model to edit!", "[TDM] Error", "OK")
		return
	else
	
	
		
		IsMenuOpenOrClosedCHANGE = 1
		-- Entry Frame
		tdm_menu.ModelChangeF = vgui.Create( "DFrame" )
		tdm_menu.ModelChangeF:SetSize( 250, 100 )
		tdm_menu.ModelChangeF:SetTitle("TEAM: ["..team.GetName(CurrentTeamID).."] Model Change")
		tdm_menu.ModelChangeF:Center()
		tdm_menu.ModelChangeF:ShowCloseButton( false )
		tdm_menu.ModelChangeF:SetDraggable( false )
		tdm_menu.ModelChangeF:MakePopup()
		

		-- The Listing Box
		NewModelIconFrame2 = 0
		CkIcF3 = 0
		tdm_menu.EntryChangeBox = vgui.Create("DButton", tdm_menu.ModelChangeF)
		tdm_menu.EntryChangeBox:SetText( SelectOneModel )
		tdm_menu.EntryChangeBox:SetPos( 25,30 )
		tdm_menu.EntryChangeBox:SetTall( 25 )
		tdm_menu.EntryChangeBox:SetWide( 200 )
		tdm_menu.EntryChangeBox.DoClick = function ( btn )
			tdm_menu.ModelButtonOptions2 = DermaMenu()
			for k,v in pairs(player_manager.AllValidModels()) do
				tdm_menu.ModelButtonOptions2:AddOption(v, function() 
					tdm_menu.EntryChangeBox:SetText( v )
					if CkIcF1 == 1 then
						tdm_menu.iconframenm2:Close()
					end
					AddChangeModel = v
					tdm_menu.iconframenm2 = vgui.Create( "DFrame" )
					tdm_menu.iconframenm2:SetPos( 400,250 )
					tdm_menu.iconframenm2:SetSize( 200, 250 )
					tdm_menu.iconframenm2:SetTitle( AddChangeModel )
					tdm_menu.iconframenm2:SetVisible( true )
					tdm_menu.iconframenm2:SetDraggable( true )
					tdm_menu.iconframenm2:ShowCloseButton( false )
					tdm_menu.iconframenm2:MakePopup()
					
					tdm_menu.newmicon2 = vgui.Create( "DModelPanel", tdm_menu.iconframenm2 )
					tdm_menu.newmicon2:SetModel( AddChangeModel )
					tdm_menu.newmicon2:SetPos(-80, 20)
					tdm_menu.newmicon2:SetSize( 350, 350 )
					tdm_menu.newmicon2:SetCamPos( Vector( 50, 100, 120 ) )
					tdm_menu.newmicon2:SetLookAt( Vector( 0, 0, 0 ) )
					
					tdm_menu.ModelFAddButtClose2 = vgui.Create( "DButton", tdm_menu.iconframenm2 )
					tdm_menu.ModelFAddButtClose2:SetSize( 85, 23 )
					tdm_menu.ModelFAddButtClose2:SetPos( 55, 220 )
					tdm_menu.ModelFAddButtClose2:SetText( "Close" )
					tdm_menu.ModelFAddButtClose2.DoClick = function( button )
						tdm_menu.iconframenm2:Close()
						NewModelIconFrame2 = 1
						CkIcF3 = 0
					return end
					NewModelIconFrame2 = 0
					CkIcF3 = 1
				end)
			end	
		tdm_menu.ModelButtonOptions2:Open()
		end	
		
		-- Close Button
		tdm_menu.ChangeAddButClose = vgui.Create( "DButton", tdm_menu.ModelChangeF )
		tdm_menu.ChangeAddButClose:SetSize( 35, 20 )
		tdm_menu.ChangeAddButClose:SetPos( 210, 3 )
		tdm_menu.ChangeAddButClose:SetText( "Close" )
		tdm_menu.ChangeAddButClose.DoClick = function( button )
			tdm_menu.ModelChangeF:Close()
			IsMenuOpenOrClosedCHANGE = 0
			if NewModelIconFrame2 == 0 then
				if CkIcF3 == 0 then return end
				tdm_menu.iconframenm2:Close()
			end
		end
		
		-- Button
		tdm_menu.ChangeAddBut = vgui.Create( "DButton", tdm_menu.ModelChangeF )
		tdm_menu.ChangeAddBut:SetSize( 65, 25 )
		tdm_menu.ChangeAddBut:SetPos( 90, 60 )
		tdm_menu.ChangeAddBut:SetText( "Change" )
		tdm_menu.ChangeAddBut.DoClick = function( button )
		GetModelListData2 = {}
		if AddChangeModel == "" || AddChangeModel == nil then
			surface.PlaySound( "apptdm/error.mp3" )
			Derma_Message("The model can't be empty, enter a valid model!", "[TDM] Error", "OK")
			return
		end
			for k, v in pairs(GetModelListData) do
				if AddChangeModel == v.Models then
					surface.PlaySound( "apptdm/error.mp3" )
					Derma_Message("The model can not be the same as another model in the list!", "[TDM] Error", "OK")
					return
				else
					if v.Models == SelectOneModel then
						v.Models = string.gsub(SelectOneModel,v.Models,AddChangeModel)
					end
					
						GetModelListData2[k] = {
						Models = v.Models
						}
				end
			end
			net.Start("GetModelListData2")
				net.WriteString(CurrentTeamID)
				net.WriteTable(GetModelListData2)
			net.SendToServer()
				
			surface.PlaySound( "apptdm/success.mp3" )
			
			tdm_menu.ModelChangeF:Close()
			IsMenuOpenOrClosedCHANGE = 0
			Derma_Message("You have successfully submitted the change!", "Team Deathmatch Gamemode", "OK")
			
			if NewModelIconFrame2 == 0 then
				if CkIcF3 == 0 then return end
				tdm_menu.iconframenm2:Close()
			end
		end
	end
end




/*
LINE BREAK
*/



-- TAB FOUR - Credits
tdm_menu.CreditScroller = vgui.Create( "DScrollPanel", tdm_menu.TabThree )
tdm_menu.CreditScroller:SetSize( 570, 180 )
tdm_menu.CreditScroller:SetPos(5,0)

CreditsTab2={} 
CreditsTab2[1]={"Creator of Gamemode: Mr. Apple,10,icon16/rosette.png,http://steamcommunity.com/id/agent_cole_phelps"}
CreditsTab2[2]={"atc,20,atc,atc"}
CreditsTab2[3]={"Thanks to Stickly Man for assisting me with menu refreshing!,30,icon16/layout.png,http://steamcommunity.com/id/Stickly_Man"}
CreditsTab2[4]={"atc,40,atc,atc"}
CreditsTab2[5]={"Thanks to Bulbosaur for helping create the overlay/gui,50,icon16/layers.png,http://steamcommunity.com/id/fbiepidemics/"}
CreditsTab2[6]={"atc,60,atc,atc"}
CreditsTab2[7]={"Thanks to ShoopDaWhoop for helping with the database selction issues,70,icon16/database_table.png,http://steamcommunity.com/id/war_spigot/"}

for k,v in pairs(CreditsTab2) do
	for k,v in pairs(v) do
		local exp = string.Explode(",",v)
		if exp[1] == "atc" then
		tdm_menu.CreditLabel = vgui.Create("DLabel", tdm_menu.CreditScroller )
		tdm_menu.CreditLabel:SetPos(20,exp[2])
		tdm_menu.CreditLabel:SetColor( Color( 0, 0, 0, 255 ) )
		tdm_menu.CreditLabel:SetText("-----------------------------------------------------")
		tdm_menu.CreditLabel:SizeToContents()
		else
		tdm_menu.CreditButton = vgui.Create( "DButton", tdm_menu.CreditScroller )
		tdm_menu.CreditButton:SetColor( Color( 0, 0, 0, 255 ) )
		tdm_menu.CreditButton:SetDrawBackground(false)
		tdm_menu.CreditButton:SetText( exp[1] )
		tdm_menu.CreditButton:SetPos( 20, exp[2])
		tdm_menu.CreditButton:SizeToContents() 
		tdm_menu.CreditButton.DoClick = function() 
			gui.OpenURL(exp[4])
		end
	end
	
	if exp[3] == "atc" then
	else
		tdm_menu.CreidtImte = vgui.Create( "DImage", tdm_menu.CreditScroller )
		tdm_menu.CreidtImte:SetPos( 0, exp[2] )                               // Set position
		tdm_menu.CreidtImte:SetImage( exp[3] )         // Set the material - relative to /materials/ directory
		tdm_menu.CreidtImte:SizeToContents() 
	end
	end 
end 



/*
LINE BREAK
*/




-- TAB ONE - Player Lists
tdm_menu.EntityListing = vgui.Create("DListView")
tdm_menu.EntityListing:SetParent(tdm_menu.TabFive)
tdm_menu.EntityListing:SetPos(7, 50)
tdm_menu.EntityListing:SetSize(250,127)
tdm_menu.EntityListing:SetMultiSelect(false)
tdm_menu.EntityListing:AddColumn("ID")
tdm_menu.EntityListing:AddColumn("Entity")
tdm_menu.EntityListing:AddColumn("X")
tdm_menu.EntityListing:AddColumn("Y")
tdm_menu.EntityListing:AddColumn("Z")
for k,v in pairs(CustomEntites) do
	tdm_menu.EntityListing:AddLine(v.id,v.name,v.xpos,v.ypos,v.zpos)
end

tdm_menu.EntitiesRemoveLabel = vgui.Create("DLabel", tdm_menu.TabFive )
tdm_menu.EntitiesRemoveLabel:SetPos(5,5)
tdm_menu.EntitiesRemoveLabel:SetColor( Color( 0, 0, 0, 255 ) )
tdm_menu.EntitiesRemoveLabel:SetText("You can manage entities here, which will spawn at map load.")
tdm_menu.EntitiesRemoveLabel:SizeToContents()

-- Select Weapon
tdm_menu.EntityListing.OnClickLine = function(_, line, __)
SelectOneEntity = line:GetValue(1)
SelectOneEntityN = line:GetValue(2)

SelectOneEntityX = line:GetValue(3)
SelectOneEntityY = line:GetValue(4)
SelectOneEntityZ = line:GetValue(5)
SelectOneEntityIs = 1
end

tdm_menu.EntityAdderB = vgui.Create("DButton", tdm_menu.TabFive)
tdm_menu.EntityAdderB:SetText( "Add" )
tdm_menu.EntityAdderB:SetPos(7, 20)
tdm_menu.EntityAdderB:SetSize( 75, 25 )
tdm_menu.EntityAdderB.DoClick = function ( btn )
if LocalPlayer():IsSuperAdmin() == false then
	surface.PlaySound( "apptdm/error.mp3" )
	Derma_Message("You are not an admin!", "[TDM] Error", "OK")
	return
elseif SelectEntityABF == 1 then
	tdm_menu.EntityABF:Close()
	SelectEntityABF = 0
	surface.PlaySound( "apptdm/error.mp3" )
	Derma_Message("You can only do one thing at a time!", "[TDM] Error", "OK")
	return 
elseif EntityRemoveIs == 1 then
	tdm_menu.EntityRemoveF:Close()
	EntityRemoveIs = 0
	surface.PlaySound( "apptdm/error.mp3" )
	Derma_Message("You can only do one thing at a time!", "[TDM] Error", "OK")
	return
end


	SelectEntityABF = 1
	tdm_menu.EntityABF = vgui.Create( "DFrame" )
	tdm_menu.EntityABF:SetSize( 250, 100 )
	tdm_menu.EntityABF:SetTitle("Entities Adder")
	tdm_menu.EntityABF:Center()
	tdm_menu.EntityABF:ShowCloseButton( false )
	tdm_menu.EntityABF:SetDraggable( false )
	tdm_menu.EntityABF:MakePopup()

	ModelEntityV = 0
	tdm_menu.EntityAdderB2 = vgui.Create("DButton", tdm_menu.EntityABF)
	tdm_menu.EntityAdderB2:SetText( "Add" )
	tdm_menu.EntityAdderB2:SetPos( 25,30 )
	tdm_menu.EntityAdderB2:SetTall( 25 )
	tdm_menu.EntityAdderB2:SetWide( 200 )
	tdm_menu.EntityAdderB2.DoClick = function ( btn )
	tdm_menu.EntityABButtonOptions2 = DermaMenu()
	for k,v in pairs(weapons.GetList()) do
		CheckBaseE = string.Explode("_",v.ClassName)
		CheckBaseE = string.Implode(" ",CheckBaseE)
			if !string.find(CheckBaseE, "base") then
				if !string.find(v.ClassName, "flechette_gun") then	
					tdm_menu.EntityABButtonOptions2:AddOption(v.ClassName, function() 
						tdm_menu.EntityAdderB2:SetText( v.ClassName )
						
						if ModelEntityV == 1 then
							tdm_menu.iconent1:Close()
						end
						SelectedEntityW = v.ClassName
						tdm_menu.iconent1 = vgui.Create( "DFrame" )
						tdm_menu.iconent1:SetPos( 300,250 )
						tdm_menu.iconent1:SetSize( 200, 250 )
						tdm_menu.iconent1:SetTitle( v.ClassName )
						tdm_menu.iconent1:SetVisible( true )
						tdm_menu.iconent1:SetDraggable( true )
						tdm_menu.iconent1:ShowCloseButton( false )
						tdm_menu.iconent1:MakePopup()
						
						tdm_menu.wnewmicon2s2 = vgui.Create( "DModelPanel", tdm_menu.iconent1 )
						tdm_menu.wnewmicon2s2:SetModel( v.WorldModel )
						tdm_menu.wnewmicon2s2:SetPos(-120, -70)
						tdm_menu.wnewmicon2s2:SetSize( 450, 450 )
						tdm_menu.wnewmicon2s2:SetCamPos( Vector( 50, 100, 0 ) )
						tdm_menu.wnewmicon2s2:SetLookAt( Vector( 0, 0, 0 ) )
						
						tdm_menu.EntityAddButtClose2s = vgui.Create( "DButton", tdm_menu.iconent1 )
						tdm_menu.EntityAddButtClose2s:SetSize( 85, 23 )
						tdm_menu.EntityAddButtClose2s:SetPos( 55, 220 )
						tdm_menu.EntityAddButtClose2s:SetText( "Close" )
						tdm_menu.EntityAddButtClose2s.DoClick = function( button )
							tdm_menu.iconent1:Close()
							ModelEntityV = 0
						return end
						
						ModelEntityV = 1
						/*
						net.Start("apple_tdm_customentities2")
							net.WriteString(v.ClassName)
						net.SendToServer()
						tdm_menu.EntityABF:Close()
						SelectEntityABF = 0
						*/
					end)
				end
			end
		end
	tdm_menu.EntityABButtonOptions2:Open()
	
	end
		
	tdm_menu.EntitySubmitButtClose2s = vgui.Create( "DButton", tdm_menu.EntityABF )
	tdm_menu.EntitySubmitButtClose2s:SetSize( 65, 25 )
	tdm_menu.EntitySubmitButtClose2s:SetPos( 90, 60 )
	tdm_menu.EntitySubmitButtClose2s:SetText( "Submit" )
	tdm_menu.EntitySubmitButtClose2s.DoClick = function( button )
	if SelectedEntityW == nil then
	surface.PlaySound( "apptdm/error.mp3" )
	Derma_Message("You have not entered a valid entity!", "Team Deathmatch Gamemode", "OK")
	return end
	net.Start("apple_tdm_customentities2")
		net.WriteString(SelectedEntityW)
	net.SendToServer()
	if ModelEntityV == 1 then
		tdm_menu.iconent1:Close()
		ModelEntityV = 0
	end
	tdm_menu.EntityABF:Close()
	SelectEntityABF = 0
	SelectedEntityW = nil
	surface.PlaySound( "apptdm/success.mp3" )
	Derma_Message("You have successfully added the entity!", "Team Deathmatch Gamemode", "OK")
	return end
		
	tdm_menu.EntityABFC = vgui.Create( "DButton", tdm_menu.EntityABF )
	tdm_menu.EntityABFC:SetSize( 35, 20 )
	tdm_menu.EntityABFC:SetPos( 210, 3 )
	tdm_menu.EntityABFC:SetText( "Close" )
	tdm_menu.EntityABFC.DoClick = function( button )
	if ModelEntityV == 1 then
		tdm_menu.iconent1:Close()
		ModelEntityV = 0
	end
	tdm_menu.EntityABF:Close()
	SelectEntityABF = 0
	return end
end


tdm_menu.EntityRemoveB = vgui.Create("DButton", tdm_menu.TabFive)
tdm_menu.EntityRemoveB:SetText( "Remove" )
tdm_menu.EntityRemoveB:SetPos(87, 20)
tdm_menu.EntityRemoveB:SetSize( 75, 25 )
tdm_menu.EntityRemoveB.DoClick = function ( btn )
if LocalPlayer():IsSuperAdmin() == false then
	surface.PlaySound( "apptdm/error.mp3" )
	Derma_Message("You are not an admin!", "[TDM] Error", "OK")
	return
elseif SelectEntityABF == 1 then
	tdm_menu.EntityABF:Close()
	SelectEntityABF = 0
	surface.PlaySound( "apptdm/error.mp3" )
	Derma_Message("You can only do one thing at a time!", "[TDM] Error", "OK")
	return
elseif EntityRemoveIs == 1 then
	tdm_menu.EntityRemoveF:Close()
	EntityRemoveIs = 0
	surface.PlaySound( "apptdm/error.mp3" )
	Derma_Message("You can only do one thing at a time!", "[TDM] Error", "OK")
	return
elseif SelectOneEntity == nil then
	surface.PlaySound( "apptdm/error.mp3" )
	Derma_Message("You have not selected a entity to remove!", "[TDM] Error", "OK")
	return
end

	EntityRemoveIs = 1
	tdm_menu.EntityRemoveF = vgui.Create( "DFrame" )
	tdm_menu.EntityRemoveF:SetSize( 250, 100 )
	tdm_menu.EntityRemoveF:SetTitle("Entities Remover")
	tdm_menu.EntityRemoveF:Center()
	tdm_menu.EntityRemoveF:ShowCloseButton( false )
	tdm_menu.EntityRemoveF:SetDraggable( false )
	tdm_menu.EntityRemoveF:MakePopup()
		
	tdm_menu.EntitiesRemoveLabel = vgui.Create("DLabel", tdm_menu.EntityRemoveF )
	tdm_menu.EntitiesRemoveLabel:SetPos(5,27)
	tdm_menu.EntitiesRemoveLabel:SetColor( Color( 0, 0, 0, 255 ) )
	tdm_menu.EntitiesRemoveLabel:SetText("This will delete the following entity, are you sure:")
	tdm_menu.EntitiesRemoveLabel:SizeToContents()
			
	tdm_menu.EntitiesRemoveLabel2 = vgui.Create("DLabel", tdm_menu.EntityRemoveF )
	tdm_menu.EntitiesRemoveLabel2:SetPos(15,44)
	tdm_menu.EntitiesRemoveLabel2:SetColor( Color( 0, 0, 0, 255 ) )
	tdm_menu.EntitiesRemoveLabel2:SetText(SelectOneEntityN)
	tdm_menu.EntitiesRemoveLabel2:SizeToContents()
			
	-- Close Button
	tdm_menu.EntitiesRemoveButtClose = vgui.Create( "DButton", tdm_menu.EntityRemoveF )
	tdm_menu.EntitiesRemoveButtClose:SetSize( 35, 20 )
	tdm_menu.EntitiesRemoveButtClose:SetPos( 210, 3 )
	tdm_menu.EntitiesRemoveButtClose:SetText( "Close" )
	tdm_menu.EntitiesRemoveButtClose.DoClick = function( button )
		tdm_menu.EntityRemoveF:Close()
	EntityRemoveIs = 0
	end

	-- Button
	tdm_menu.EntitiesRemoveButt = vgui.Create( "DButton", tdm_menu.EntityRemoveF )
	tdm_menu.EntitiesRemoveButt:SetSize( 65, 25 )
	tdm_menu.EntitiesRemoveButt:SetPos( 90, 60 )
	tdm_menu.EntitiesRemoveButt:SetText( "Delete" )
	tdm_menu.EntitiesRemoveButt.DoClick = function( button )
	net.Start("apple_tdm_customentities5")
		net.WriteString(SelectOneEntity)
	net.SendToServer()
		
		surface.PlaySound( "apptdm/success.mp3" )
		tdm_menu.EntityRemoveF:Close()
		EntityRemoveIs = 0
		SelectOneEntity = nil
		Derma_Message("You have successfully submitted the change!", "Team Deathmatch Gamemode", "OK")
	return
	end
end


tdm_menu.EntityGotoB = vgui.Create("DButton", tdm_menu.TabFive)
tdm_menu.EntityGotoB:SetText( "Goto" )
tdm_menu.EntityGotoB:SetPos(173, 20)
tdm_menu.EntityGotoB:SetSize( 35, 25 )
tdm_menu.EntityGotoB.DoClick = function ( btn )
if LocalPlayer():IsSuperAdmin() == false then
	surface.PlaySound( "apptdm/error.mp3" )
	Derma_Message("You are not an admin!", "[TDM] Error", "OK")
	return
elseif SelectOneEntityX == nil then 
	surface.PlaySound( "apptdm/error.mp3" )
	Derma_Message("You have not selected a entity to goto!", "[TDM] Error", "OK")
return end
surface.PlaySound( "apptdm/success.mp3" )
	net.Start("apple_tdm_customentitiesr9")
		net.WriteString(SelectOneEntityX)
		net.WriteString(SelectOneEntityY)
		net.WriteString(SelectOneEntityZ)
	net.SendToServer()
SelectOneEntityX = nil
SelectOneEntityY = nil
SelectOneEntityZ = nil
end

tdm_menu.EntityReloadB = vgui.Create("DButton", tdm_menu.TabFive)
tdm_menu.EntityReloadB:SetText( "Reload" )
tdm_menu.EntityReloadB:SetPos(216, 20)
tdm_menu.EntityReloadB:SetSize( 40, 25 )
tdm_menu.EntityReloadB.DoClick = function ( btn )
if LocalPlayer():IsSuperAdmin() == false then
	surface.PlaySound( "apptdm/error.mp3" )
	Derma_Message("You are not an admin!", "[TDM] Error", "OK")
	return
end
surface.PlaySound( "apptdm/success.mp3" )
Derma_Message("You have successfully reloaded the entities!", "Team Deathmatch Gamemode", "OK")
	net.Start("apple_tdm_customentitiesr42")
		net.WriteString("doesnothing")
	net.SendToServer()
end


-- TAB Four - Change Log
tdm_menu.ChangeLogScroller = vgui.Create( "DScrollPanel", tdm_menu.TabFour )
tdm_menu.ChangeLogScroller:SetSize( 570, 180 )
tdm_menu.ChangeLogScroller:SetPos(5,0)

ChangeLog2={} 
ChangeLog2[1]={"[6/20/14] Started the Remake of the Gamemode,10,icon16/tux.png"}
ChangeLog2[2]={"atc,20,atc,atc"}
ChangeLog2[3]={"[6/21/14] Replaced For Database Instead of Static Teams,30,icon16/chart_line.png"}
ChangeLog2[4]={"atc,40,atc,atc"}
ChangeLog2[5]={"[6/22/14] Added Menu With Basic Features,50,icon16/add.png"}
ChangeLog2[6]={"atc,60,atc,atc"}
ChangeLog2[7]={"[6/22/14] Added ChangeLog & Credits Tab,70,icon16/add.png"}
ChangeLog2[8]={"atc,80,atc,atc"}
ChangeLog2[9]={"[6/23/14] Added Ability to Change Model,90,icon16/add.png"}
ChangeLog2[10]={"atc,100,atc,atc"}
ChangeLog2[11]={"[6/23/14] Added Ability to Change Team,110,icon16/add.png"}
ChangeLog2[12]={"atc,120,atc,atc"}
ChangeLog2[13]={"[6/23/14] Added Safety Features to Database to Ignore SQL Injections,130,icon16/add.png"}
ChangeLog2[14]={"atc,140,atc,atc"}
ChangeLog2[15]={"[6/24/14] Added ULX Compatibility (not yet used),150,icon16/add.png"}
ChangeLog2[16]={"atc,160,atc,atc"}
ChangeLog2[17]={"[6/25/14] Removed ability to kill self,170,icon16/cancel.png"}
ChangeLog2[18]={"atc,180,atc,atc"}
ChangeLog2[19]={"[6/26/14] Added ability to edit models and weapons for teams,190,icon16/add.png"}
ChangeLog2[20]={"atc,200,atc,atc"}
ChangeLog2[21]={"[6/27/14] Added ability to edit teams,210,icon16/add.png"}
ChangeLog2[22]={"atc,220,atc,atc"}
ChangeLog2[23]={"[6/27/14] Added HUD by Bulbosaur via credits,230,icon16/add.png"}
ChangeLog2[24]={"atc,240,atc,atc"}
ChangeLog2[25]={"[6/29/14] Added ability to create team spawn points,250,icon16/add.png"}
ChangeLog2[26]={"atc,260,atc,atc"}
ChangeLog2[27]={"[7/02/14] Added custom entity spawner,270,icon16/add.png"}
ChangeLog2[28]={"atc,280,atc,atc"}
ChangeLog2[29]={"[7/04/14] Added kill streaks messages,290,icon16/add.png"}
ChangeLog2[30]={"atc,300,atc,atc"}
ChangeLog2[31]={"[7/06/14] Added challenge rewards (Crouch Killing is currently only challenge),310,icon16/add.png"}
ChangeLog2[32]={"atc,320,atc,atc"}
ChangeLog2[33]={"[7/08/14] Added points ability (currently not able to spend them),330,icon16/add.png"}
ChangeLog2[34]={"atc,340,atc,atc"}
ChangeLog2[35]={"[7/12/14] Added statistics tab in menu,350,icon16/add.png"}
ChangeLog2[36]={"atc,360,atc,atc"}
ChangeLog2[37]={"[7/12/14] Added rank name and current points to the points tab in menu,370,icon16/add.png"}
ChangeLog2[38]={"atc,380,atc,atc"}
ChangeLog2[39]={"[1/09/15] Fixed being able to kill self,390,icon16/pencil.png"}
ChangeLog2[40]={"atc,400,atc,atc"}
ChangeLog2[41]={"[7/12/14] Added ability to switch to normal Deathmatch or Teamdeathmatch via Game Settings,410,icon16/add.png"}


for k,v in pairs(ChangeLog2) do
	for k,v in pairs(v) do
	local exp = string.Explode(",",v)
		if exp[1] == "atc" then
		tdm_menu.ChangeLogLebel2 = vgui.Create("DLabel", tdm_menu.CreditScroller )
		tdm_menu.ChangeLogLebel2:SetPos(20,exp[2])
		tdm_menu.ChangeLogLebel2:SetColor( Color( 0, 0, 0, 255 ) )
		tdm_menu.ChangeLogLebel2:SetText("-----------------------------------------------------")
		tdm_menu.ChangeLogLebel2:SizeToContents()
		else
		tdm_menu.ChangeLogLebel = vgui.Create("DLabel", tdm_menu.ChangeLogScroller )
		tdm_menu.ChangeLogLebel:SetPos(20,exp[2])
		tdm_menu.ChangeLogLebel:SetColor( Color( 0, 0, 0, 255 ) )
		tdm_menu.ChangeLogLebel:SetText(exp[1])
		tdm_menu.ChangeLogLebel:SizeToContents()
		end
		
		if exp[3] == "atc" then
		else
			tdm_menu.ChangeImage = vgui.Create( "DImage", tdm_menu.ChangeLogScroller )
			tdm_menu.ChangeImage:SetPos( 0, exp[2] )                               // Set position
			tdm_menu.ChangeImage:SetImage( exp[3] )         // Set the material - relative to /materials/ directory
			tdm_menu.ChangeImage:SizeToContents() 
		end
	end
end

-- TAB Six - Choose a goal
tdm_menu.ChooseAWin = vgui.Create("DLabel", tdm_menu.TabSix)
tdm_menu.ChooseAWin:SetPos(10,5)
tdm_menu.ChooseAWin:SetColor( Color( 0, 0, 0, 255 ) )
tdm_menu.ChooseAWin:SetFont("default")
tdm_menu.ChooseAWin:SetText("Set Goal:")
tdm_menu.ChooseAWin:SizeToContents()

tdm_menu.GameWinS = vgui.Create( "Slider", tdm_menu.TabSix )
tdm_menu.GameWinS:SetPos( 3, 10 ) 
tdm_menu.GameWinS:SetWide( 200 )
tdm_menu.GameWinS:SetMin( -1 )
tdm_menu.GameWinS:SetMax( 100 )
tdm_menu.GameWinS:SetValue( DEFAULT_GOAL_VALUE )
tdm_menu.GameWinS:SetDecimals( 0 )
tdm_menu.GameWinS.OnValueChanged = function( panel, value )
if LocalPlayer():IsSuperAdmin() != true then
--surface.PlaySound( "apptdm/error.mp3" )
--chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),'] ',Color(255,255,255,255),'You are not an admin!')
--Derma_Message("You can only change something one at a time!", "[TDM] Error", "OK")
return end
	net.Start("apple_tdm_customgoal")
		net.WriteString(tostring(value))
	net.SendToServer()
end


-- TAB Six - Team Deathmatch or Deathmatch
tdm_menu.ChooseTDMorDM = vgui.Create("DLabel", tdm_menu.TabSix)
tdm_menu.ChooseTDMorDM:SetPos(10,72)
tdm_menu.ChooseTDMorDM:SetColor( Color( 0, 0, 0, 255 ) )
tdm_menu.ChooseTDMorDM:SetFont("default")
tdm_menu.ChooseTDMorDM:SetText("Current Gamemode:")
tdm_menu.ChooseTDMorDM:SizeToContents()

if LocalPlayer():Team() == 1000 then
tdm_menu.ChooseTDMorDM = vgui.Create("DLabel", tdm_menu.TabSix)
tdm_menu.ChooseTDMorDM:SetPos(112,72)
tdm_menu.ChooseTDMorDM:SetColor( Color( 255, 0, 0, 255 ) )
tdm_menu.ChooseTDMorDM:SetFont("default")
tdm_menu.ChooseTDMorDM:SetText("Deathmatch")
tdm_menu.ChooseTDMorDM:SizeToContents()
else
tdm_menu.ChooseTDMorDM = vgui.Create("DLabel", tdm_menu.TabSix)
tdm_menu.ChooseTDMorDM:SetPos(112,72)
tdm_menu.ChooseTDMorDM:SetColor( Color( 255, 0, 0, 255 ) )
tdm_menu.ChooseTDMorDM:SetFont("default")
tdm_menu.ChooseTDMorDM:SetText("Team Deathmatch")
tdm_menu.ChooseTDMorDM:SizeToContents()
end

tdm_menu.GameIsDM = vgui.Create( "DButton", tdm_menu.TabSix )
tdm_menu.GameIsDM:SetSize( 100, 20 )
tdm_menu.GameIsDM:SetPos( 3, 90 )
tdm_menu.GameIsDM:SetText( "Switch to DM" )
tdm_menu.GameIsDM.DoClick = function( button )
if LocalPlayer():IsSuperAdmin() != true then
surface.PlaySound( "apptdm/error.mp3" )
chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),'] ',Color(255,255,255,255),'You are not an admin!')
Derma_Message("You are not an administrator!", "[TDM] Error", "OK")
return end
	net.Start("apple_tdm_is_dm")
		net.WriteString(tostring(1))
	net.SendToServer()
	surface.PlaySound( "apptdm/success.mp3" )
	end
tdm_menu.GameIsTDM = vgui.Create( "DButton", tdm_menu.TabSix )
tdm_menu.GameIsTDM:SetSize( 100, 20 )
tdm_menu.GameIsTDM:SetPos( 3, 115 )
tdm_menu.GameIsTDM:SetText( "Switch to TDM" )
tdm_menu.GameIsTDM.DoClick = function( button )
if LocalPlayer():IsSuperAdmin() != true then
surface.PlaySound( "apptdm/error.mp3" )
chat.AddText(Color(255,255,255,255), '[',Color(255,0,0,255), 'TDM',Color(255,255,255,255),'] ',Color(255,255,255,255),'You are not an admin!')
Derma_Message("You are not an administrator!", "[TDM] Error", "OK")
return end
	net.Start("apple_tdm_is_dm")
		net.WriteString(tostring(0))
	net.SendToServer()
	surface.PlaySound( "apptdm/success.mp3" )
	end
	
	
/*
tdm_menu.GameIsDM = vgui.Create( "Slider", tdm_menu.TabSix )
tdm_menu.GameIsDM:SetPos( 3, 45 ) 
tdm_menu.GameIsDM:SetWide( 200 )
tdm_menu.GameIsDM:SetMin( 0 )
tdm_menu.GameIsDM:SetMax( 1 )
tdm_menu.GameIsDM:SetValue( DEFAULT_DMorTDM_VALUE )
tdm_menu.GameIsDM:SetDecimals( 0 )
tdm_menu.GameIsDM.OnValueChanged = function( panel, value )
	net.Start("apple_tdm_is_dm")
		net.WriteString(tostring(value))
	net.SendToServer()
end
*/


/*
tdm_menu.ChooseFF = vgui.Create("DLabel", tdm_menu.TabSix)
tdm_menu.ChooseFF:SetPos(10,45)
tdm_menu.ChooseFF:SetColor( Color( 0, 0, 0, 255 ) )
tdm_menu.ChooseFF:SetFont("default")
tdm_menu.ChooseFF:SetText("Friendly Fire:")
tdm_menu.ChooseFF:SizeToContents()

tdm_menu.FFCheckbox = vgui.Create( "DCheckBox", tdm_menu.TabSix )
tdm_menu.FFCheckbox:SetPos( 10, 60 )
tdm_menu.FFCheckbox.OnChange = function () -- This is DoClick
if LocalPlayer():IsSuperAdmin() != true then
--surface.PlaySound( "apptdm/error.mp3" )
--Derma_Message("You are not an admin!", "[TDM] Error", "OK")
return end
if tdm_menu.FFCheckbox:GetChecked() == true then
net.Start("TDMFriendlyFire")
	net.WriteString(0)
net.SendToServer()
else
net.Start("TDMFriendlyFire")
	net.WriteString(1)
net.SendToServer()
end
end
*/

-- TAB Six - Teams Lists
tdm_menu.MapListing = vgui.Create("DListView")
tdm_menu.MapListing:SetParent(tdm_menu.TabSix)
tdm_menu.MapListing:SetPos(350, 7)
tdm_menu.MapListing:SetSize(220,170)
tdm_menu.MapListing:AddColumn("ID")
tdm_menu.MapListing:AddColumn("Maps")
tdm_menu.MapListing:SetMultiSelect(false)
for k,v in pairs(CustomMapsList) do
	tdm_menu.MapListing:AddLine(k,v.name)
end

-- Check Model Listing
tdm_menu.MapListing.OnClickLine = function(_, line, __)
SelectOneMap = line:GetValue(1)
SelectedMapIs = 1
end

tdm_menu.MapButton = vgui.Create("DButton", tdm_menu.TabSix)
tdm_menu.MapButton:SetText( "Add Map" )
tdm_menu.MapButton:SetPos(265, 30)
tdm_menu.MapButton:SetSize( 75, 25 )
tdm_menu.MapButton.DoClick = function ( btn )
if LocalPlayer():IsSuperAdmin() != true then
surface.PlaySound( "apptdm/error.mp3" )
Derma_Message("You are not an admin!", "[TDM] Error", "OK")
return end
tdm_menu.MenuMenuOptions = DermaMenu()
for k,v in pairs(CustomMaps) do
	tdm_menu.MenuMenuOptions:AddOption(v, function()  
		net.Start("TDMTDMListMap")
			net.WriteString(tostring(v))
		net.SendToServer()
		surface.PlaySound( "apptdm/success.mp3" )
		Derma_Message("You have successfully added a new map!", "Team Deathmatch Gamemode", "OK")
	end )		
	tdm_menu.MenuMenuOptions:Open()
end	
end


tdm_menu.MapButtonD = vgui.Create("DButton", tdm_menu.TabSix)
tdm_menu.MapButtonD:SetText( "Delete Map" )
tdm_menu.MapButtonD:SetPos(265, 70)
tdm_menu.MapButtonD:SetSize( 75, 25 )
tdm_menu.MapButtonD.DoClick = function ( btn )
if LocalPlayer():IsSuperAdmin() != true then
surface.PlaySound( "apptdm/error.mp3" )
Derma_Message("You are not an admin!", "[TDM] Error", "OK")
return 
elseif SelectedMapIs == 0 then
surface.PlaySound( "apptdm/error.mp3" )
Derma_Message("You have not selected a map to remove!", "[TDM] Error", "OK")
return end
net.Start("TDMDeleteMap")
	net.WriteString(SelectOneMap)
net.SendToServer()
	surface.PlaySound( "apptdm/success.mp3" )
	Derma_Message("You have successfully removed a map!", "Team Deathmatch Gamemode", "OK")
SelectedMapIs = 0
end




/* Some more bullshit is going in this retarded file
This file should never be touched, as said before.
*/

tdm_menu.ChangeImageN = vgui.Create( "DImage", tdm_menu.TabSeven )
tdm_menu.ChangeImageN:SetPos( 0, 5 )                               // Set position
tdm_menu.ChangeImageN:SetImage( "icon16/information.png" )         // Set the material - relative to /materials/ directory
tdm_menu.ChangeImageN:SizeToContents() 

tdm_menu.PSName = vgui.Create("DLabel", tdm_menu.TabSeven)
tdm_menu.PSName:SetPos(17,6)
tdm_menu.PSName:SetColor( Color( 0, 0, 0, 255 ) )
tdm_menu.PSName:SetFont("default")
tdm_menu.PSName:SetText("Welcome, "..LocalPlayer():Nick().." to Point Shop 1.3 Beta. Updates will come to this every so often")
tdm_menu.PSName:SizeToContents()

tdm_menu.ChangeImageP = vgui.Create( "DImage", tdm_menu.TabSeven )
tdm_menu.ChangeImageP:SetPos( 0, 20 )                               // Set position
tdm_menu.ChangeImageP:SetImage( "icon16/money.png" )         // Set the material - relative to /materials/ directory
tdm_menu.ChangeImageP:SizeToContents() 

tdm_menu.PSPointsT = vgui.Create("DLabel", tdm_menu.TabSeven)
tdm_menu.PSPointsT:SetPos(17,21)
tdm_menu.PSPointsT:SetColor( Color( 0, 0, 0, 255 ) )
tdm_menu.PSPointsT:SetFont("default")
tdm_menu.PSPointsT:SetText("Your Points: ")
tdm_menu.PSPointsT:SizeToContents()

tdm_menu.PSPoints = vgui.Create("DLabel", tdm_menu.TabSeven)
tdm_menu.PSPoints:SetPos(82,21)
tdm_menu.PSPoints:SetColor( Color( 255, 0, 0, 255 ) )
tdm_menu.PSPoints:SetFont("default")
tdm_menu.PSPoints:SetText(GetValueForPoints)
tdm_menu.PSPoints:SizeToContents()

tdm_menu.ChangeImageR = vgui.Create( "DImage", tdm_menu.TabSeven )
tdm_menu.ChangeImageR:SetPos( 0, 35 )                               // Set position
tdm_menu.ChangeImageR:SetImage( "icon16/asterisk_orange.png" )         // Set the material - relative to /materials/ directory
tdm_menu.ChangeImageR:SizeToContents() 

tdm_menu.PSPointsR = vgui.Create("DLabel", tdm_menu.TabSeven)
tdm_menu.PSPointsR:SetPos(17,37)
tdm_menu.PSPointsR:SetColor( Color( 0, 0, 0, 255 ) )
tdm_menu.PSPointsR:SetFont("default")
tdm_menu.PSPointsR:SetText("Your Rank: ")
tdm_menu.PSPointsR:SizeToContents()

tdm_menu.PSPointRN = vgui.Create("DLabel", tdm_menu.TabSeven)
tdm_menu.PSPointRN:SetPos(77,37)
tdm_menu.PSPointRN:SetColor( Color( 255, 0, 0, 255 ) )
tdm_menu.PSPointRN:SetFont("default")
tdm_menu.PSPointRN:SetText(GetValueForRank)
tdm_menu.PSPointRN:SizeToContents()

tdm_menu.ClassesListing = vgui.Create("DListView")
tdm_menu.ClassesListing:SetParent(tdm_menu.TabSeven)
tdm_menu.ClassesListing:SetPos(7, 60)
tdm_menu.ClassesListing:SetSize(250,115)
tdm_menu.ClassesListing:SetMultiSelect(false)
tdm_menu.ClassesListing:AddColumn("Name")
tdm_menu.ClassesListing:AddColumn("Points")
tdm_menu.ClassesListing:AddColumn("Rank")
for k,v in pairs(player.GetAll()) do
	tdm_menu.ClassesListing:AddLine(v:Nick(),v:Frags(),v:Deaths())
end



tdm_menu.StName = vgui.Create("DLabel", tdm_menu.TabEight)
tdm_menu.StName:SetPos(17,6)
tdm_menu.StName:SetColor( Color( 0, 0, 0, 255 ) )
tdm_menu.StName:SetFont("MenuLarge2")
tdm_menu.StName:SetText("Player Statics: "..LocalPlayer():Nick())
tdm_menu.StName:SizeToContents()

tdm_menu.StKills = vgui.Create("DLabel", tdm_menu.TabEight)
tdm_menu.StKills:SetPos(17,21)
tdm_menu.StKills:SetColor( Color( 0, 0, 0, 255 ) )
tdm_menu.StKills:SetFont("default")
tdm_menu.StKills:SetText("Your Total Kills: ")
tdm_menu.StKills:SizeToContents()

tdm_menu.StKillsP = vgui.Create("DLabel", tdm_menu.TabEight)
tdm_menu.StKillsP:SetPos(100,21)
tdm_menu.StKillsP:SetColor( Color( 255, 0, 0, 255 ) )
tdm_menu.StKillsP:SetFont("default")
tdm_menu.StKillsP:SetText(StatKillsP)
tdm_menu.StKillsP:SizeToContents()

tdm_menu.StDeaths = vgui.Create("DLabel", tdm_menu.TabEight)
tdm_menu.StDeaths:SetPos(17,31)
tdm_menu.StDeaths:SetColor( Color( 0, 0, 0, 255 ) )
tdm_menu.StDeaths:SetFont("default")
tdm_menu.StDeaths:SetText("Your Total Deaths: ")
tdm_menu.StDeaths:SizeToContents()

tdm_menu.StDeathsP = vgui.Create("DLabel", tdm_menu.TabEight)
tdm_menu.StDeathsP:SetPos(115,31)
tdm_menu.StDeathsP:SetColor( Color( 255, 0, 0, 255 ) )
tdm_menu.StDeathsP:SetFont("default")
tdm_menu.StDeathsP:SetText(StatDeathP)
tdm_menu.StDeathsP:SizeToContents()

tdm_menu.StRatios = vgui.Create("DLabel", tdm_menu.TabEight)
tdm_menu.StRatios:SetPos(17,41)
tdm_menu.StRatios:SetColor( Color( 0, 0, 0, 255 ) )
tdm_menu.StRatios:SetFont("default")
tdm_menu.StRatios:SetText("K/D Ratio: ")
tdm_menu.StRatios:SizeToContents()

tdm_menu.StRatiosP = vgui.Create("DLabel", tdm_menu.TabEight)
tdm_menu.StRatiosP:SetPos(75,37)
tdm_menu.StRatiosP:SetColor( Color( 255, 0, 0, 255 ) )
tdm_menu.StRatiosP:SetFont("default")
tdm_menu.StRatiosP:SetText(string.Left(tostring(StatKillsP/StatDeathP),4))
tdm_menu.StRatiosP:SetWrap(false)
--tdm_menu.StRatiosP:SizeToContents()

tdm_menu.StTime = vgui.Create("DLabel", tdm_menu.TabEight)
tdm_menu.StTime:SetPos(17,61)
tdm_menu.StTime:SetColor( Color( 0, 0, 0, 255 ) )
tdm_menu.StTime:SetFont("default")
tdm_menu.StTime:SetText("Total Time in Hours: ")
tdm_menu.StTime:SizeToContents()

tdm_menu.StTimeP = vgui.Create("DLabel", tdm_menu.TabEight)
tdm_menu.StTimeP:SetPos(120,61)
tdm_menu.StTimeP:SetColor( Color( 255, 0, 0, 255 ) )
tdm_menu.StTimeP:SetFont("default")
tdm_menu.StTimeP:SetText(math.Round(StatTimeP/60))
tdm_menu.StTimeP:SizeToContents()

tdm_menu.StTime2 = vgui.Create("DLabel", tdm_menu.TabEight)
tdm_menu.StTime2:SetPos(17,51)
tdm_menu.StTime2:SetColor( Color( 0, 0, 0, 255 ) )
tdm_menu.StTime2:SetFont("default")
tdm_menu.StTime2:SetText("Total Time in Minutes: ")
tdm_menu.StTime2:SizeToContents()

tdm_menu.StTimeP2 = vgui.Create("DLabel", tdm_menu.TabEight)
tdm_menu.StTimeP2:SetPos(132,51)
tdm_menu.StTimeP2:SetColor( Color( 255, 0, 0, 255 ) )
tdm_menu.StTimeP2:SetFont("default")
tdm_menu.StTimeP2:SetText(math.Round(StatTimeP))
tdm_menu.StTimeP2:SizeToContents()







-- Tab Listing
tdm_menu.MainMenuSheet:AddSheet( "Info", tdm_menu.TabOne, "icon16/information.png", false, false, "General Information." )
tdm_menu.MainMenuSheet:AddSheet( "Team Config", tdm_menu.TabTwo, "icon16/key.png", false, false, "Team Configurations" )
tdm_menu.MainMenuSheet:AddSheet( "Entities Config", tdm_menu.TabFive, "icon16/sitemap_color.png", false, false, "Entities Configurations" )
tdm_menu.MainMenuSheet:AddSheet( "Game Config", tdm_menu.TabSix, "icon16/plugin.png", false, false, "Game Configurations" )
tdm_menu.MainMenuSheet:AddSheet( "Point Shop", tdm_menu.TabSeven, "icon16/money.png", false, false, "Point Shop" )
tdm_menu.MainMenuSheet:AddSheet( "Statistics", tdm_menu.TabEight, "icon16/vcard.png", false, false, "Personal Statistics" )
tdm_menu.MainMenuSheet:AddSheet( "Change Log", tdm_menu.TabFour, "icon16/new.png", false, false, "Change Log" )
tdm_menu.MainMenuSheet:AddSheet( "Credits", tdm_menu.TabThree, "icon16/heart.png", false, false, "Credits" )
end



 
function tdm_menu.toggleMenu() -- This is a toggleable menu technically
	if tdm_menu.MainMenuFrame == nil || tdm_menu.MainMenuFrame == NULL then -- If somehow you are able to work at computer speed at open this before the server creates it for you in realtime, it will create it here
		tdm_menu.initialize() -- If a player joins, it create the menu
		gui.EnableScreenClicker( true ) -- This will turn the mouse on for toggle mode
	else
		if tdm_menu.MainMenuFrame:IsVisible() then -- Checks to see if nenu is visible or not
			gui.EnableScreenClicker( false ) -- menu is off then mouse is off
			tdm_menu.icon:SetModel( LocalPlayer():GetModel()) -- Fixes the model if changed
			tdm_menu.MainMenuFrame:SetVisible(false) --menu will be set off
			tdm_menu.PlayerListing:Clear() -- Clears the list of players
			tdm_menu.TeamListing:Clear() -- Clears the list of teams
				for k,v in pairs(player.GetAll()) do
					tdm_menu.PlayerListing:AddLine(v:Nick(),v:Frags(),v:Deaths(),team.GetName(v:Team())) -- Adds the listing back
				end
				for k,v in pairs(AddTeams2) do
					tdm_menu.TeamListing:AddLine(k,v.tname) -- If youre editing teams this needs to be reset
				end
		else
			gui.EnableScreenClicker( true ) -- mouse on
			tdm_menu.icon:SetModel( LocalPlayer():GetModel()) -- Fixes the model if changed
			tdm_menu.MainMenuFrame:SetVisible(true) -- menu on
			tdm_menu.PlayerListing:Clear() -- Clears the list of players
			tdm_menu.TeamListing:Clear() -- Clears the list of teams
			tdm_menu.ClassesListing:Clear() -- Clears the list of teams
			tdm_menu.PSName:SetText("Welcome, "..LocalPlayer():Nick().." to Point Shop 1.3 Beta. Updates will come to this every so often")
			tdm_menu.StName:SetText("Player Statics: "..LocalPlayer():Nick())
				for k,v in pairs(player.GetAll()) do
					tdm_menu.PlayerListing:AddLine(v:Nick(),v:Frags(),v:Deaths(),team.GetName(v:Team())) -- Adds the listing back
					tdm_menu.ClassesListing:AddLine(v:Nick(),v:Frags(),v:Deaths())
				end
				for k,v in pairs(AddTeams2) do
					tdm_menu.TeamListing:AddLine(k,v.tname) -- If youre editing teams this needs to be reset
				end
		end
	end
end
concommand.Add( "tdm_menu", tdm_menu.toggleMenu )



function apple_tdm_updatelist() -- This updates the entire menu if any change happens at all
	if tdm_menu.MainMenuFrame == nil || tdm_menu.MainMenuFrame == NULL then -- If the menu doesn't exist, create it
		tdm_menu.initialize() -- If a player joins, it create the menu
		tdm_menu.MainMenuFrame:SetVisible(false) -- Closes the menu before you know it's open
		gui.EnableScreenClicker( false ) -- Closes the mouse before you know its open
		SelectedModelIs = 0 -- Resets Model Listing
		SelectedTeamID = 0 -- Resets Team Listings
		SelectedWeaponIs = 0 -- Resets Weapon Listing
	else
			timer.Simple(0.4, function() -- I made this because I don't want thing happening in real time due to bugs
			tdm_menu.icon:SetModel( LocalPlayer():GetModel()) -- Fixes the model if changed
			tdm_menu.PlayerListing:Clear() -- Clears the list of players
			tdm_menu.TeamListing:Clear() -- Clears the list of teams
			tdm_menu.ModelListing:Clear() -- Clears the model listing
			tdm_menu.WeaponsListing:Clear() -- Clears the weapon listing
			tdm_menu.ClassesListing:Clear() -- Clears the weapon listing
			tdm_menu.PSName:SetText("Welcome, "..LocalPlayer():Nick().." to Point Shop 1.3 Beta. Updates will come to this every so often")
			tdm_menu.StName:SetText("Player Statics: "..LocalPlayer():Nick())
			SelectedModelIs = 0 -- Resets Model Listing
			SelectedTeamID = 0 -- Resets Team Listings
			SelectedWeaponIs = 0 -- Resets Weapon Listing
				for k,v in pairs(player.GetAll()) do
					tdm_menu.PlayerListing:AddLine(v:Nick(),v:Frags(),v:Deaths(),team.GetName(v:Team())) -- Adds the listing back
					tdm_menu.ClassesListing:AddLine(v:Nick(),v:Frags(),v:Deaths())
				end
				for k,v in pairs(AddTeams2) do
					tdm_menu.TeamListing:AddLine(k,v.tname) -- If youre editing teams this needs to be reset
				end
			end)
	end
end
usermessage.Hook("apple_tdm_updatelist", apple_tdm_updatelist)



function apple_tdm_updatelistp() -- This updates the entire menu if any change happens at all
	if tdm_menu.MainMenuFrame == nil || tdm_menu.MainMenuFrame == NULL then -- If the menu doesn't exist, create it
		tdm_menu.initialize() -- If a player joins, it create the menu
		tdm_menu.MainMenuFrame:SetVisible(false) -- Closes the menu before you know it's open
		gui.EnableScreenClicker( false ) -- Closes the mouse before you know its open
	else
			timer.Simple(0.4, function() -- I made this because I don't want thing happening in real time due to bugs
			tdm_menu.icon:SetModel( LocalPlayer():GetModel()) -- Fixes the model if changed
			tdm_menu.PlayerListing:Clear() -- Clears the list of players
			tdm_menu.ClassesListing:Clear() -- Clears the list of players
				for k,v in pairs(player.GetAll()) do
					tdm_menu.PlayerListing:AddLine(v:Nick(),v:Frags(),v:Deaths(),team.GetName(v:Team())) -- Adds the listing back
					tdm_menu.ClassesListing:AddLine(v:Nick(),v:Frags(),v:Deaths())
				end
			end)
	end
end
usermessage.Hook("apple_tdm_updatelistp", apple_tdm_updatelistp)



function apple_tdm_updateliste() -- This updates the entire menu if any change happens at all
	if tdm_menu.MainMenuFrame == nil || tdm_menu.MainMenuFrame == NULL then -- If the menu doesn't exist, create it
		tdm_menu.initialize() -- If a player joins, it create the menu
		tdm_menu.MainMenuFrame:SetVisible(false) -- Closes the menu before you know it's open
		gui.EnableScreenClicker( false ) -- Closes the mouse before you know its open
	else
			timer.Simple(0.5, function() -- I made this because I don't want thing happening in real time due to bugs
				tdm_menu.EntityListing:Clear()
				for k,v in pairs(CustomEntites) do
					tdm_menu.EntityListing:AddLine(k,v.name,v.xpos,v.ypos,v.zpos)
				end
			end)
	end
end
usermessage.Hook("apple_tdm_updateliste", apple_tdm_updateliste)


function apple_tdm_updategoal(data) -- This updates the entire menu if any change happens at all
DEFAULT_GOAL_VALUE = 0
DEFAULT_GOAL_VALUE = data:ReadShort()
	if tdm_menu.MainMenuFrame == nil || tdm_menu.MainMenuFrame == NULL then -- If the menu doesn't exist, create it
		tdm_menu.initialize() -- If a player joins, it create the menu
		tdm_menu.MainMenuFrame:SetVisible(false) -- Closes the menu before you know it's open
		gui.EnableScreenClicker( false ) -- Closes the mouse before you know its open
	else
		timer.Simple(0.5, function() -- I made this because I don't want thing happening in real time due to bugs
			tdm_menu.GameWinS:SetValue( DEFAULT_GOAL_VALUE )
		end)
	end
end
usermessage.Hook("apple_tdm_setgoal", apple_tdm_updategoal)


function apple_tdm_updatetdmordm(data) -- This updates the entire menu if any change happens at all
DEFAULT_DMorTDM_VALUE = 0
DEFAULT_DMorTDM_VALUE = data:ReadShort()
end
usermessage.Hook("apple_tdm_is_dm", apple_tdm_updatetdmordm)


/*
function apple_tdm_setff(data) -- This updates the entire menu if any change happens at all
DEFAULT_FF_VALUE2 = 1
DEFAULT_FF_VALUE2 = data:ReadShort()
	if tdm_menu.MainMenuFrame == nil || tdm_menu.MainMenuFrame == NULL then -- If the menu doesn't exist, create it
		tdm_menu.initialize() -- If a player joins, it create the menu
		tdm_menu.MainMenuFrame:SetVisible(false) -- Closes the menu before you know it's open
		gui.EnableScreenClicker( false ) -- Closes the mouse before you know its open
	else
		timer.Simple(0.5, function() -- I made this because I don't want thing happening in real time due to bugs
			tdm_menu.FFCheckbox:SetValue( DEFAULT_FF_VALUE2 )
		end)
	end
end
usermessage.Hook("apple_tdm_setff", apple_tdm_setff)
*/

function apple_tdm_updatemap(data) -- This updates the entire menu if any change happens at all
	if tdm_menu.MainMenuFrame == nil || tdm_menu.MainMenuFrame == NULL then -- If the menu doesn't exist, create it
		tdm_menu.initialize() -- If a player joins, it create the menu
		tdm_menu.MainMenuFrame:SetVisible(false) -- Closes the menu before you know it's open
		gui.EnableScreenClicker( false ) -- Closes the mouse before you know its open
	else
		timer.Simple(0.5, function() -- I made this because I don't want thing happening in real time due to bugs
		tdm_menu.MapListing:Clear()
				for k,v in pairs(CustomMapsList) do
					tdm_menu.MapListing:AddLine(k,v.name)
				end
		end)
	end
end
usermessage.Hook("apple_tdm_updatemap", apple_tdm_updatemap)


function apple_tdm_psppoints(data) -- This updates the entire menu if any change happens at all
GetValueForPoints = data:ReadString()
GetValueForRank = data:ReadString()
	if tdm_menu.MainMenuFrame == nil || tdm_menu.MainMenuFrame == NULL then -- If the menu doesn't exist, create it
		tdm_menu.initialize() -- If a player joins, it create the menu
		tdm_menu.MainMenuFrame:SetVisible(false) -- Closes the menu before you know it's open
		gui.EnableScreenClicker( false ) -- Closes the mouse before you know its open
	else
		timer.Simple(0.9, function() -- I made this because I don't want thing happening in real time due to bugs
			tdm_menu.PSPoints:SetText(GetValueForPoints)
			tdm_menu.PSPointRN:SetText(GetValueForRank)
		end)
	end
end
usermessage.Hook("apple_tdm_psppoints", apple_tdm_psppoints)


function TDMStatsKill(data) -- This updates the entire menu if any change happens at all
StatKillsP = data:ReadString()
	if tdm_menu.MainMenuFrame == nil || tdm_menu.MainMenuFrame == NULL then -- If the menu doesn't exist, create it
		tdm_menu.initialize() -- If a player joins, it create the menu
		tdm_menu.MainMenuFrame:SetVisible(false) -- Closes the menu before you know it's open
		gui.EnableScreenClicker( false ) -- Closes the mouse before you know its open
	else
		timer.Simple(0.5, function() -- I made this because I don't want thing happening in real time due to bugs
			tdm_menu.StKillsP:SetText(StatKillsP)
			tdm_menu.StRatiosP:SetText(string.Left(tostring(StatKillsP/StatDeathP),4))
		end)
	end
end
usermessage.Hook("TDMStatsKill", TDMStatsKill)


function TDMStatsDeaths(data) -- This updates the entire menu if any change happens at all
StatDeathP = data:ReadString()
	if tdm_menu.MainMenuFrame == nil || tdm_menu.MainMenuFrame == NULL then -- If the menu doesn't exist, create it
		tdm_menu.initialize() -- If a player joins, it create the menu
		tdm_menu.MainMenuFrame:SetVisible(false) -- Closes the menu before you know it's open
		gui.EnableScreenClicker( false ) -- Closes the mouse before you know its open
	else
		timer.Simple(0.5, function() -- I made this because I don't want thing happening in real time due to bugs
			tdm_menu.StDeathsP:SetText(StatDeathP)
			tdm_menu.StRatiosP:SetText(string.Left(tostring(StatKillsP/StatDeathP),4))
		end)
	end
end
usermessage.Hook("TDMStatsDeaths", TDMStatsDeaths)


function TDMStatsTime(data) -- This updates the entire menu if any change happens at all
StatTimeP = math.Round(data:ReadString())
	if tdm_menu.MainMenuFrame == nil || tdm_menu.MainMenuFrame == NULL then -- If the menu doesn't exist, create it
		tdm_menu.initialize() -- If a player joins, it create the menu
		tdm_menu.MainMenuFrame:SetVisible(false) -- Closes the menu before you know it's open
		gui.EnableScreenClicker( false ) -- Closes the mouse before you know its open
	else
		timer.Simple(0.5, function() -- I made this because I don't want thing happening in real time due to bugs
				tdm_menu.StTimeP:SetText(math.Round(StatTimeP/60))
				tdm_menu.StTimeP2:SetText(StatTimeP)
		end)
	end
end
usermessage.Hook("TDMStatsTime", TDMStatsTime)

/*
net.Receive( "apple_tdm_pointshopdata3", function() 
	if tdm_menu.MainMenuFrame == nil || tdm_menu.MainMenuFrame == NULL then -- If the menu doesn't exist, create it
		tdm_menu.initialize() -- If a player joins, it create the menu
		tdm_menu.MainMenuFrame:SetVisible(false) -- Closes the menu before you know it's open
		gui.EnableScreenClicker( false ) -- Closes the mouse before you know its open
	else
		timer.Simple(0.5, function() -- I made this because I don't want thing happening in real time due to bugs
				tdm_menu.ClassesListing:Clear()
				for k, v in pairs(net.ReadTable()) do
				--	tdm_menu.ClassesListing:AddLine(v.Name,v.Points,v.Rank)
				MsgN(v.Name)
				MsgN(v.Points)
				MsgN(v.Rank)
				end
		end)
	end
end)
*/